question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Runtime error with WebJobs.Extensions.CosmosDB in console app for .NET Framework 4.8

See original GitHub issue

I receive the following runtime error when configuring webjobs with cosmosdb:

MissingMethodException: Method not found: 'Microsoft.Azure.Documents.Client.ConnectionPolicy Microsoft.Azure.Documents.ChangeFeedProcessor.DocumentCollectionInfo.get_ConnectionPolicy()'.

Repro steps

Empty console project, for a .NET 4.8, and add latest relevant libraries.

1. Set up the host builder, with build.AddCosmosDB()

My code example:

IHostBuilder hostBuilder = new HostBuilder()
               .UseEnvironment("Development")
               .ConfigureAppConfiguration((hostContext, config) => {
                   config.AddJsonFile("appsettings.json", optional: true);
                   config.AddEnvironmentVariables();
               })
               .ConfigureWebJobs(builder => {
                   builder.AddExecutionContextBinding();
                   builder.AddAzureStorageCoreServices();
                   builder.AddCosmosDB();
               })
               .ConfigureLogging((context, builder) => {
                   // add logging for debug
                   builder.AddConsole();
               });

using (IHost host = hostBuilder.Build())
{
    await host.RunAsync();
}

You can add the connection string to the builder instead of the Trigger if you want.

2. Set up the CosmosDBTrigger with the correct information.

I used the example code:

https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-cosmosdb-v2-trigger?tabs=csharp

With my relevant information.

Please note, setting this up you will run into: https://github.com/Azure/azure-webjobs-sdk-extensions/issues/573

We are using Webjobs V3 (thus azure functions V2), therefore we want to use the CosmosDB extension not the DocumentDb extension recommended in the above link.

However, by setting an alias on the documentdb.core we are able to circumvent this issue.

Also, if you added the connection string to the builder, you do not need to include it with the Trigger.

3. With everything set up correctly, you will be able to start the code. When starting the code you receive the below stack:

Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException
  HResult=0x80131500
  Message=Error indexing method 'CosmosTrigger'
  Source=Microsoft.Azure.WebJobs.Host
  StackTrace:
   at Microsoft.Azure.WebJobs.Host.RecoverableException.TryRecover(ILogger logger) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Exceptions\RecoverableException.cs:line 81
   at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexer.<IndexTypeAsync>d__17.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexer.cs:line 94
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexProvider.<CreateAsync>d__16.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexProvider.cs:line 97
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexProvider.<GetAsync>d__15.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Indexers\FunctionIndexProvider.cs:line 69
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.Host.Executors.JobHostContextFactory.<Create>d__21.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Executors\JobHostContextFactory.cs:line 108
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.JobHost.<InitializeHostAsync>d__35.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\JobHost.cs:line 347
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.WebJobs.JobHost.<StartAsyncCore>d__21.MoveNext() in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\JobHost.cs:line 95
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Extensions.Hosting.Internal.Host.<StartAsync>d__9.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.<RunAsync>d__4.MoveNext()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.<RunAsync>d__4.MoveNext()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at LogicAppWebJob.Program.<Main>d__0.MoveNext() in C:\src\Willowglade\Testing\LogicAppWebJob\LogicAppWebJob\Program.cs:line 52

Inner Exception 1:
MissingMethodException: Method not found: 'Microsoft.Azure.Documents.Client.ConnectionPolicy Microsoft.Azure.Documents.ChangeFeedProcessor.DocumentCollectionInfo.get_ConnectionPolicy()'.

Expected behavior

It should be listening to the CosmosDb changefeed, and no errors should occur.

Actual behavior

Receive a runtime error.

Known workarounds

None at the moment.

Related information

Provide any related information

  • The latest version of all relevant packages.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
benpap24commented, May 3, 2021

Hi, if I understand it right, by now we still cannot use Microsoft.Azure.WebJobs.Extensions.CosmosDB for net461, since the PR is not merged yet, right? @fabiocav Can you share how did you solve the problem ? @benpap24

As a temporary workaround we changed the reference of the two libraries and found a combination that functioned correctly. You should have access of both of these when downloaded the packages from nuget.

We changed ChangeFeedProcessor to netstandard2.0:

FROM:
Microsoft.Azure.DocumentDB.ChangeFeedProcessor.2.3.2\lib\net45\Microsoft.Azure.Documents.ChangeFeedProcessor.dll
TP:
Microsoft.Azure.DocumentDB.ChangeFeedProcessor.2.3.2\lib\netstandard2.0\Microsoft.Azure.Documents.ChangeFeedProcessor.dll

and we changed Microsoft.Azure.DocumentDB to net45:

FROM:
Microsoft.Azure.DocumentDB.2.13.1\lib\net461\Microsoft.Azure.Documents.Client.dll
TO:
Microsoft.Azure.DocumentDB.2.13.1\lib\net45\Microsoft.Azure.Documents.Client.dll

We did not have to change Microsoft.Azure.DocumentDB.Core, and am still using netstandard1.6

Should this have worked? I’m not 100% sure, but fortunately we were lucky and everything does function correctly.

1reaction
ealsurcommented, May 3, 2021

@cloudsere The PR is still in progress and when merged, it will be a whole new major version of the extension. When the new version is released in the upcoming months, it would solve the dependency issue because it uses other packages altogether.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot use Microsoft.Azure.WebJobs.Extensions. ...
NET Framework Console application (much like you would for a web job), ... error CS0433: The type 'Document' exists in both 'Microsoft.
Read more >
Troubleshoot issues with the Azure Functions trigger for ...
This article discusses common issues, workarounds, and diagnostic steps when you're using the Azure Functions trigger for Azure Cosmos DB.
Read more >
How to use the WebJobs SDK - Azure App Service
WebJobs host. The host is a runtime container for functions. The Host listens for triggers and calls functions.
Read more >
Azure Functions runtime versions overview
Azure Functions supports multiple versions of the runtime. Learn the differences between them and how to choose the one that's right for ...
Read more >
Support for Framework 4.8.1 in Azure Webjobs
Is there support for 4.8.1 in Azure Webjobs I have upgraded a complex solution to 4.8.1 and although the websites and other components...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found