I am trying to generate authcontext with below code with the latest version of ADAL package (3.13.9) I am getting exception. However, I downgrade the ADAL version to v2.22.302111727 it works without an issue. I am using visual studio 2017. What is wrong with 3.13.9?
authContext = new AuthenticationContext(authority, true);
System.TypeInitializationException occurred HResult=0x80131534
Message=The type initializer for 'Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext' threw an exception.
Source=Microsoft.IdentityModel.Clients.ActiveDirectory StackTrace:
at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext..ctor(String authority, Boolean validateAuthority) at DestinationProvider.AADToken.d__4.MoveNext() in D:\Repo\MyProjects\nv\nv\DestinationProvider\AADToken.cs:line 32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at ReplLoop.ReplLoop.d__1.MoveNext() in D:\Repo\MyProjects\nv\nv\nvReplLoop\ReplLoop.cs:line 52Inner Exception 1: TypeInitializationException: The type initializer for 'Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformPlugin' threw an exception.
Inner Exception 2: AdalException: Assembly required for the platform not found. Make sure assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.13.8.999, Culture=neutral, PublicKeyToken=31bf3856ad364e35' exists
Inner Exception 3: FileNotFoundException: Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.13.8.999, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
It sounds like you might have hit this issue:
https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/511
I'm using isabekyan's workaround, as that has resolved the issue for me.
They suggest adding a call to the below code before using authenticationContext
private static void SomeMethodToLinkPlatform()
{
var creds = new UserPasswordCredential("testUser", "SomePassword");
}
Based on the error message, the reference is incorrect. If you were refer to the 3.13.9
version of ADAL, it shouldn't try to load the 3.13.8.999
version of Microsoft.IdentityModel.Clients.ActiveDirectory.Platform
.
Please ensure that the other assemblies you were referring is not depending on this library. Then you can use the Nuget to update the ADAL to the latest version(3.13.9.1126
). After you upgrade, both the version of Microsoft.IdentityModel.Clients.ActiveDirectory
and Microsoft.IdentityModel.Clients.ActiveDirectory.Platform
should be 3.13.9.1126
.
Please let me know if it helps.
User contributions licensed under CC BY-SA 3.0