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?

Scotty H
  • 6,432
  • 6
  • 41
  • 94

1 Answers1

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.

Matias Quaranta
  • 13,907
  • 1
  • 22
  • 47
  • 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. – Danie Sep 27 '19 at 15:10
  • In my case I have other packages that depende on the full framework, for example the BulkExecutor. What could I do? – moarra Apr 29 '20 at 17:21
  • You can use Bulk Executor preview versions or use the new Bulk support in V3 SDK https://devblogs.microsoft.com/cosmosdb/introducing-bulk-support-in-the-net-sdk/ – Matias Quaranta Apr 29 '20 at 17:35