Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Functions DocumentClient could not load type from assembly exception

I have an Azure Function v2 that calls into an utility library, which in turn instantiates a DocumentClient. When running my function locally, it throws an exception on this line:

_client = new DocumentClient(new Uri(cosmosDbEndpoint), cosmosDbAuthKey, Storage.SerializerSettings, connectionPolicy);

System.Private.CoreLib: Exception while executing function: ComponentDesignInserter-Http-UploadFiles. Microsoft.Azure.Documents.Client: Could not load type 'System.Diagnostics.Eventing.EventProviderTraceListener' from assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

My utility library is .NET Framework 4.7. My Azure Function v2 project is .NET Standard 2.0. Is that a problem?

Or is this symptomatic of some dependency that I need to install in the Azure Function v2 project? A dependency that the utility library has but the Azure Function v2 project doesn't?

like image 318
Scotty H Avatar asked Mar 09 '19 01:03

Scotty H


1 Answers

As you mention, the problem is that you are using a NET Framework 4.7 library from a NET Standard 2.0 project.

Make sure that in your NET 4.7 library, you are using the Cosmos DB Core SDK: https://www.nuget.org/packages/Microsoft.Azure.DocumentDB.Core/

Not the NET Full Framework package (https://www.nuget.org/packages/Microsoft.Azure.DocumentDB).

In your Azure Functions V2 project, you also need to use the same nuget (Core). If you are using the Microsoft.Azure.WebJobs.Extensions.CosmosDB package, it is already included.

like image 165
Matias Quaranta Avatar answered Nov 15 '22 00:11

Matias Quaranta