Azure Authentication - 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform' no working

BradBlythBradBlyth AUMember

Hi,

I'm doing a simple AD Authentication with Xamarin.iOS and a .NET Azure Mobile Service. I have a simple call ...

_try
{
AuthenticationContext addContext = new AuthenticationContext(aadAuthority);
AuthenticationResult aResult = null;
aResult = await addContext.AcquireTokenSilentAsync (addContext.Authority, aadClientId);
}
catch(Exception ex)
{
}
_

but on instantiation of my AuthenticationContext I get an error

ex {System.TypeInitializationException: An exception was thrown by the type initializer for Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext ---> System.TypeInitializationException: An exception was thrown by the type initializer for Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformPlugin ---> Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException: Assembly required for the platform not found. Make sure assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' exists ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform' or one of its dependencies. The system cannot find the file specified. File name: 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform' at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity) [0x00081] in /Users/builder/data/lanes/1962/8b265d64/source/mono/mcs/class/corlib/System/AppDomain.cs:706 at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef) [0x00000] in /Users/builder/data/lanes/1962/8b265d64/source/mono/mcs/class/corlib/System/AppDomain.cs:674 at System.Reflection.Assembly.Load (System.Reflection.AssemblyName assemblyRef) [0x00000] in /Users/builder/data/lanes/1962/8b265d64/source/mono/mcs/class/corlib/System.Reflection/Assembly.cs:551 at Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformPlugin.LoadPlatformSpecificAssembly () [0x00024] in :0 --- End of inner exception stack trace --- at Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformPlugin.LoadPlatformSpecificAssembly () [0x00056] in :0 at Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformPlugin.InitializeByAssemblyDynamicLinking () [0x00000] in :0 at Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformPlugin..cctor () [0x0001b] in :0 --- End of inner exception stack trace --- at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext..cctor () [0x00000] in :0 --- End of inner exception stack trace --- at xTester.FirstViewController+c__async0.MoveNext () [0x00067] in /Users/cba-user/Projects/xTester/xTester/FirstViewController.cs:89 } System.TypeInitializationException

I have installed the Microsoft.IdentityModel.Clients.ActiveDirectory Package (3.0) and have the Microsoft.IdentityModel.Clients.ActiveDirectory & Microsoft.IdentityModel.Clients.ActiveDirectory.Platform references in my project, though I can only reference Microsoft.IdentityModel.Clients.ActiveDirectory in code -> Microsoft.IdentityModel.Clients.ActiveDirectory.Platform is not recognised (I think this is the problem though not sure how to fix it).

Any Help please?

Posts

  • JamesHarris.7031JamesHarris.7031 GBUniversity ✭✭

    Thanks - this saved my morning! Do you know why it needs the initialise? I have it working on Android and Windows without this.

  • This gave me the error "AdalInitializer is inaccessible due to its protection level". The class is marked as internal

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai
    edited April 2017

    The main thing here is the need to call something in the Microsoft.IdentityModel.Clients.ActiveDirectory.Platform assembly that the static analysis of your code will pick up so the assembly is linked in, so try the following in the AppDelegate's FinishedLaunching method:

    if (false) {
        PlatformParameters pp = new PlatformParameters(Window.RootViewController);
     }
    

    NOTE: If you are referencing an assembly and nothing in your source code calls into or refers to anything in that assembly, the linker assumes you don't need it at all and leaves it out.

Sign In or Register to comment.