In Asp.Net Core solution targeted to 4.6.1 full Framework I am using 2.1.1 Microsoft.Azure.ActiveDirectory.GraphClient.dll
In MSTest tests library TestMethods I am getting exception:
System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Data.Services.Client, Version=5.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
The wild thing that nuspec requires version 5.6.4, but DLL actually references 5.6.3.
Extract from dotPeek:
// Assembly Microsoft.Azure.ActiveDirectory.GraphClient, Version=2.1.10.0, Culture=neutral, PublicKeyToken=null
// Assembly references:
// Microsoft.Data.Services.Client, Version=5.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// Microsoft.Data.Edm, Version=5.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// Microsoft.Data.OData, Version=5.6.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
.nuget\packages\Microsoft.Azure.ActiveDirectory.GraphClient\2.1.1\Microsoft.Azure.ActiveDirectory.GraphClient.nuspec
<dependencies>
<dependency id="Microsoft.Data.Services.Client" version="5.6.4" />
<dependency id="Microsoft.Data.Edm" version="5.6.4" />
<dependency id="Microsoft.Data.OData" version="5.6.4" />
<dependency id="System.Spatial" version="5.6.4" />
</dependencies>
I've tried to install Microsoft.Data.Services.Client 5.6.3, but NuGet reported that Microsoft.Data.Odata requires 5.6.4
I've tried to install Microsoft.Data.Odata 5.6.3, but NuGet reported that Microsoft.Azure.ActiveDirectory.GraphClient require 5.6.4
I tried to use assemblyBinding, but it doesn't work for me (I've tried suggestions from assemblybinding does not work in mstest)
Any suggestions how to make Microsoft.Data.Services.Client loaded?
Can I somehow overwrite nuspec dependencies?
Update: I've created isolated library with single TestMethod, that has the problem.
The FIX: The problem was that in app.config in assemblyBinding/ bindingRedirect I've used File Version instead of Assembly Version, which is different for this assembly (File Version=5.6.4.62175, but Assembly Version=5.6.4.0). Correct configuration is
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" />
</dependentAssembly>
</assemblyBinding>
I am testing using Visual Studio 2017, and install the package Microsoft.Azure.ActiveDirectory.GraphClient
with version 2.1.1
. I also check the dependency version of Microsoft.Data.Services.Client
is version 5.6.3
as you mentioned.
However, I also checked the version of Microsoft.Data.Services.Client.dll in the bin folder is 5.6.4.0
and it works well for me. Please use this version to see whether it is helpful.
And here is the part of deps.json
file for your reference:
{
"runtimeTarget": {
"name": ".NETFramework,Version=v4.6.1/win7-x86",
"signature": "d7dc1119a66d1c2bf3e9f2c55e2b0432742f00d1"
},
"compilationOptions": {
"defines": [
"TRACE",
"DEBUG",
"NET461"
],
"languageVersion": "",
"platform": "x86",
"allowUnsafe": false,
"warningsAsErrors": false,
"optimize": false,
"keyFile": "",
"emitEntryPoint": true,
"xmlDoc": false,
"debugType": "portable"
},
"targets": {
".NETFramework,Version=v4.6.1": {
"consoleapp1/1.0.0": {
"dependencies": {
"Microsoft.AspNetCore.Server.Kestrel": "1.0.3",
"Microsoft.Azure.ActiveDirectory.GraphClient": "2.1.1"
},
"compile": {
"ConsoleApp1.exe": {}
}
},
...
"microsoft.azure.activedirectory.graphclient/2.1.1": {
"dependencies": {
"Microsoft.Data.Edm": "5.6.4",
"Microsoft.Data.OData": "5.6.4",
"Microsoft.Data.Services.Client": "5.6.4",
"System.Spatial": "5.6.4"
},
"compile": {
"lib/portable-net4+sl5+win+wpa+wp8/Microsoft.Azure.ActiveDirectory.GraphClient.dll": {}
}
},
"microsoft.data.edm/5.6.4": {
"compile": {
"lib/net40/Microsoft.Data.Edm.dll": {}
}
},
"microsoft.data.odata/5.6.4": {
"dependencies": {
"Microsoft.Data.Edm": "5.6.4",
"System.Spatial": "5.6.4"
},
"compile": {
"lib/net40/Microsoft.Data.OData.dll": {}
}
},
"microsoft.data.services.client/5.6.4": {
"dependencies": {
"Microsoft.Data.OData": "5.6.4"
},
"compile": {
"lib/net40/Microsoft.Data.Services.Client.dll": {}
}
},
...
}
}
}
For the redirecting assembly in a unit test project, add the config like steps below:
1 .add a config file testAssemblyName.dll.config(eg. my project's name is ConsoleApp1.Test then the config file should be ConsoleApp1.Test.dll.config) with content below:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Services.Client" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.OData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" />
</dependentAssembly>
</assemblyBinding>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Edm" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.4.0" newVersion="5.6.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Copy to Output Directory
with the value Copy if newer
to make sure that the config is copy to the bin/debug folder.After that the tests run successfully.