Runtime error with WebJobs.Extensions.CosmosDB in console app for .NET Framework 4.8
See original GitHub issueI 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:
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:
- Created 2 years ago
- Comments:9 (3 by maintainers)
Top GitHub Comments
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:
and we changed Microsoft.Azure.DocumentDB to net45:
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.
@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.