Hello,
We are attempting to upgrade from Microsoft.Azure.DocumentDB to Microsoft.Azure.Cosmos SDK v3. We are running into the following exception when instantiating the v3 CosmosClient:
_The type initializer for 'Microsoft.Azure.Documents.UserAgentContainer' threw an exception._
We are also using Cosmos Table API in our project, so not sure if there is some dependency conflict in the libraries we are using for Cosmos SQL and the Table API.
We thought maybe there is a conflict with a previous version of the Cosmos SDKs and it's dependencies, so we have been spending the last few days testing the different versions of the v3 SDK to make sure no old library references are hanging around.
Here is the list of current Cosmos related libraries installed in our project:
Microsoft.Azure.Cosmos v3.6.0
Microsoft.Azure.Cosmos.Direct v3.4.2
Microsoft.Azure.Cosmos.Table v1.0.6
Microsoft.Azure.DocumentDB.Core v.2.9.3
We've also tested upgrading Microsoft.Azure.Cosmos.Table to v2.0.0-preview to test eliminating the dependency on Microsoft.Azure.DocumentDB.Core, but we still received the same type exception.
At this point, we've burned so much time trying to get to the bottom of what's going on that I wanted to put the question out to the larger group to see if there is anyone else using the SQL SDK and Table API SDK who is running into this type exception problem.
@gegoodwin any chance you can provide a repo?
@j82w Unfortunately, no, as this is a private library for our company. Is there something specific I could pull out to share that could help troubleshoot?
It's hard to debug dependency issues without the project file.
@gegoodwin I could not repro, I created the following CSPROJ:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.6.0" />
<PackageReference Include="Microsoft.Azure.Cosmos.Table" Version="1.0.6" />
<PackageReference Include="Microsoft.Azure.DocumentDB.Core" Version="2.9.3" />
</ItemGroup>
</Project>
Then created a Program.cs with this:
static void Main(string[] args)
{
CosmosClient client = new CosmosClient("AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==");
client.CreateDatabaseIfNotExistsAsync("test").GetAwaiter().GetResult();
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=http;AccountName=localhost;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==;TableEndpoint=http://localhost:8902/;");
}
And it works, no errors.
Do you maybe have other projects involved (Project References) that might have different versions of the same packages and no binding resolution?
@ealsur thank you for the sanity check. We definitely have some sort of dependency issue going on. We've re-written our wrapper class for the Cosmos Client and are now getting a new exception related to System.Net.Http having a version conflict.
I appreciate everyone's help so far; we'll keep working internally to get the problem resolved. I'll post an update when we get to the bottom of the dependency problem.
A dependency conflict on System.Net.Http definitively points at something off on project references. I'm going to close this issue because we could not find a problem with our repro. Please re-open if you rule out any dependency conflict / redirect.
To close the loop on this issue, the cause of the dependency issue with System.Net.Http was a result of Microsoft.Azure.CosmosDB.Table's dependency on Microsoft.Azure.DocumentDB.Core adding a reference to System.Net.Http in app.config with a different version than what was being used in our .NET Standard (.NET Framework 4.7) project. Once we commented out the reference to System.Net.Http in app.config, the problem went away.
Thanks again for your replies. They helped keep us on track to find the solution.
Most helpful comment
To close the loop on this issue, the cause of the dependency issue with System.Net.Http was a result of Microsoft.Azure.CosmosDB.Table's dependency on Microsoft.Azure.DocumentDB.Core adding a reference to System.Net.Http in app.config with a different version than what was being used in our .NET Standard (.NET Framework 4.7) project. Once we commented out the reference to System.Net.Http in app.config, the problem went away.
Thanks again for your replies. They helped keep us on track to find the solution.