I'm referencing two (nuget) packages from my app and setting up KeyVault DI configuration. Both the packages reference Microsoft.IdentityModel.Clients.ActiveDirectory nuget package. One references major version 3, the other major version 4. Major version 4 removes the dll Microsoft.IdentityModel.Clients.ActiveDirectory.Platform
.
When I call AddAzureKeyVault()
with a certificate to add the KV configuration I get an AssemblyNotFoundException
for the dll Microsoft.IdentityModel.Clients.ActiveDirectory.Platform
at runtime. The file is correctly not there and I've redirected the binding of the associated dll to the major version so why is it being requested at runtime? Is there a way of binding a call to Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll
back to Microsoft.IdentityModel.Clients.ActiveDirectory.dll
? I've provided binding redirects and tried multiple permutations.
To replicate, from a console app you can reference packages:
Microsoft.Extensions.Configuration.AzureKeyVault 2.2.0 Microsoft.IdentityModel.Client.ActiveDirectory 4.5.1
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Extensions.Configuration;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var cb = new ConfigurationBuilder();
using (var store = new X509Store(StoreName.My, StoreLocation.LocalMachine))
{
store.Open(OpenFlags.ReadOnly);
var certs = store.Certificates.Find(X509FindType.FindBySubjectName, "DummyValue", false);
cb.AddAzureKeyVault("https://this-is-a-dummy.vault.azure.net", "dummy-client-id", certs.OfType<X509Certificate2>().Single());
store.Close();
}
var config = cb.Build();
}
}
}
Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.14.2.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Pre-bind FusionLog
LOG: DisplayName = Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.14.2.11, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified)
LOG: Appbase = file:///C:/Code/sandbox/why-doesnt-this-work/ConsoleApp1/ConsoleApp1/bin/Debug/
LOG: Initial PrivatePath = NULL Calling assembly : Microsoft.Extensions.Configuration.AzureKeyVault, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60.