azure-functions-host: CosmosDB Trigger is not working in Visual Studio development

I’m developing my functions in Visual Studio and providing testing also from Visual Studio. My function “CosmosDB Trigger” using Local CosmosDB Emulator. When I press to debug I started to see in Output(VS) errors and through 30 sec I see error in console.

Here is my function

[FunctionName("WorkDocumentDBTrigger")]
   public static void Run([CosmosDBTrigger("AlfredDentDocumentDBWE01", "Clinic",
        ConnectionStringSetting = "CosmosDBEmulator",
        CreateLeaseCollectionIfNotExists = true,
        LeaseCollectionName = "ClinicLease")]
        IReadOnlyList<Document> documents,
        TraceWriter log)
    {
        log.Info($"{DateTimeOffset.Now} [INFO][WorkDocumentDBTrigger] Start");
    }

Here is Output Stack trace

An exception is thrown:“System.Net.WebException” в System.dll An exception is thrown: “System.Net.WebException” в System.dll An exception is thrown: “System.Net.Sockets.SocketException” в System.dll DocDBTrace Information: 0 : RefreshLocationAsync() refreshing locations DocDBTrace Information: 0 : Set WriteEndpoint https://127.0.0.1:8081/ ReadEndpoint https://127.0.0.1:8081/ DocDBTrace Information: 0 : DocumentClient with id 2 initialized at endpoint: https://localhost:8081/ with ConnectionMode: Direct, connection Protocol: Tcp, and consistency level: null DocDBTrace Information: 0 : RefreshLocationAsync() refreshing locations DocDBTrace Information: 0 : Set WriteEndpoint https://127.0.0.1:8081/ ReadEndpoint https://127.0.0.1:8081/ An exception is thrown: “System.Security.Authentication.AuthenticationException” in System.dll An exception is thrown:“System.Security.Authentication.AuthenticationException” in System.dll An exception is thrown:“System.Security.Authentication.AuthenticationException” in mscorlib.dll An exception is thrown: “Microsoft.Azure.Documents.GoneException” in Microsoft.Azure.Documents.Client.dll An exception is thrown: “System.Security.Authentication.AuthenticationException” in System.dll An exception is thrown: “System.Security.Authentication.AuthenticationException” in System.dll An exception is thrown:“System.Security.Authentication.AuthenticationException” in mscorlib.dll An exception is thrown: “Microsoft.Azure.Documents.GoneException” in mscorlib.dll An exception is thrown: “Microsoft.Azure.Documents.GoneException” in mscorlib.dll An exception is thrown: “Microsoft.Azure.Documents.GoneException” in mscorlib.dll An exception is thrown: “Microsoft.Azure.Documents.GoneException” in Microsoft.Azure.Documents.Client.dll An exception is thrown: “Microsoft.Azure.Documents.GoneException” in mscorlib.dll An exception is thrown: “Microsoft.Azure.Documents.GoneException” in mscorlib.dll DocDBTrace Information: 0 : Вызвано исключение: “Microsoft.Azure.Documents.GoneException” in mscorlib.dll An exception is thrown: “Microsoft.Azure.Documents.GoneException” in mscorlib.dll An exception is thrown: “Microsoft.Azure.Documents.GoneException” in mscorlib.dll GetOpenConnection failed: RID: dbs/AlfredDentDocumentDBWE01, ResourceType Database, Op: (operationType: Read, resourceType: Database), Address: rntbd://172.19.32.1:10251/apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, Exception: Microsoft.Azure.Documents.GoneException: Message: The requested resource is no longer available at the server. ActivityId: fbb9e255-983a-4ece-a7d0-bcf08d1ea4f9, Request URI: rntbd://172.19.32.1:10251/apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/ —> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to authentication results in System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult) в System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result) в System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult) в System.Threading.Tasks.TaskFactory1.FromAsyncCoreLogic(IAsyncResult iar, Func2 endFunction, Action1 endAction, Task1 promise, Boolean requiresSynchronization) — End the stack trace from the previous location where the exception occurred— в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) в Microsoft.Azure.Documents.RntbdConnection.<PerformHandshakes>d__20.MoveNext() — End trace of internal exception stack— в Microsoft.Azure.Documents.RntbdConnection.<PerformHandshakes>d__20.MoveNext() — End the stack trace from the previous location where the exception occurred— в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) в System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) в Microsoft.Azure.Documents.RntbdConnection.<Open>d__0.MoveNext() —End the stack trace from the previous location where the exception occurred— в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) в Microsoft.Azure.Documents.RntbdConnectionDispenser.<OpenNewConnection>d__0.MoveNext() —End the stack trace from the previous location where the exception occurred— в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) в Microsoft.Azure.Documents.ConnectionPool.<GetOpenConnection>d__0.MoveNext() — End the stack trace from the previous location where the exception occurred— в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) в Microsoft.Azure.Documents.ConnectionPoolManager.<GetOpenConnection>d__0.MoveNext() — End the stack trace from the previous location where the exception occurred— в System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) в System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) в Microsoft.Azure.Documents.RntbdTransportClient.<InvokeStoreAsync>d__0.MoveNext()

Here is console error

A ScriptHost error has occurred The listener for function “*******” was unable to start. Microsoft.Azure.Documents.Client: Service is currently unavailable. Microsoft.Azure.Documents.Client: The requested resource is no longer available at the server.

CosmosDB Emulator 1.17.43.5 Microsoft.Azure.WebJobs.Extenstions.DocumentDB 1.1.0-beta-4 Microsoft.NET.Sdk.Functions 1.0.6

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (10 by maintainers)

Most upvoted comments

I had the same error, where our Function output console running in Visual Studio debug mode showed this:

DocDBTrace Information: 0 : Set WriteEndpoint https://127.0.0.1:8081/ ReadEndpoint https://127.0.0.1:8081/
DocDBTrace Information: 0 : GetOpenConnection failed: RID: dbs/CCM, ResourceType Database, Op: (operationType: Read, resourceType: Database), Address: rntbd://192.168.10.2:10251/apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, Exception: Microsoft.Azure.Documents.GoneException: Message: The requested resource is no longer available at the server.
ActivityId: b1baa8cd-d305-444e-8916-bab18f5bf07a, Request URI: rntbd://192.168.10.2:10251/apps/DocDbApp/services/DocDbMaster0/partitions/780e44f4-38c8-11e6-8106-8cdcd42c33be/replicas/1p/ ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.

As you can see the CosmosDBTrigger in the Function tries to connect to the Cosmos DB Emulator at rntbd://192.168.10.2:10251. This address might not be directly your local machine, but in my case a virtual network adapter created by VirtualBox, VMWare, HyperV or something alike.

Solution: disable the virtual network adapter, or add 192.168.10.2 localhost (or your equivalent IP address) to your local host file. This solved the connection error of the CosmosDBTrigger and the function connected again to the Cosmos DB Emulator change feed.