Azure Functions DocumentClient could not load type from assembly exception
Asked Answered
F

1

5

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?

Fax answered 9/3, 2019 at 1:8 Comment(1)
You shouldn't have a .NET Standard project reference a .NET Framework project.Abradant
M
8

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.

Minorca answered 12/3, 2019 at 15:27 Comment(3)
This worked, thanks! I had one .NET Core, and one .NET Framework application, and then i changed to Microsoft.Azure.DocumentDB.Core in the .NET Framework project and it started to work.Caravette
In my case I have other packages that depende on the full framework, for example the BulkExecutor. What could I do?Blakely
You can use Bulk Executor preview versions or use the new Bulk support in V3 SDK devblogs.microsoft.com/cosmosdb/…Minorca

© 2022 - 2024 — McMap. All rights reserved.