1
votes

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 52

Inner 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.

2
Do you fix this issue now? If not, please don't hesitate to let me know which step block you.Fei Xue - MSFT
Actually No. I switched to v2.22.302111727 which works. 3.13.9 and 3.13.8 both giving the same error.Shiju Samuel
The issue is casued by the incorrect assembly reference.To narrow down the issue, you can create a fresh project and only install the 3.13.9 version of ADAL and compare the the version of assemblies then add the library one by one to check which library cause this issue. If you still have the problem, you may share a code project on GitHub to help to reproduce this issue.Fei Xue - MSFT

2 Answers

1
votes

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");
    }
0
votes

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.