0

I have a Xamarin.iOS project and I want to authenticate with Azure. The end goal is to not have the user login, and to authenticate behind the scenes. When I instantiate AuththenticationContext I get this Error. "Could not load file or assembly 'Microsoft.IdentityModel.Clients.ActiveDirectory.Platform'". I installed Microsoft.IndentityModel.Clients.ActiveDirectory v3.13.9 from Nuget and the using statement is at the top of the code. The DLL is set to copy local. I don't know why this is not working. I even unintalled the Nuget Package and added the DLL's to the project and referenced them directly and got the same error. Below is the code that I am trying to make work. Again it breaks when AuthenticationContext is instantiated so I cant even test the rest of it. I have used the following two websites for guidance, https://blog.xamarin.com/authenticate-xamarin-mobile-apps-using-azure-active-directory/

I found this "bug" here, but the fix does not work, nor does it make sense to me. Im not sure where to put the code and I get the access error as well. https://forums.xamarin.com/discussion/45425/azure-authentication-microsoft-identitymodel-clients-activedirectory-platform-no-working

 var authContext = new AuthenticationContext(aadInstance);
        ClientCredential clientCredential = new ClientCredential(clientId, appKey);

            // ADAL includes an in memory cache, so this call will only send a message to the server if the cached token is expired.
                 AuthenticationResult result =  authContext.AcquireTokenAsync(AMServiceResourceId, clientCredential).Result;

            WebRequest Request =
                WebRequest.Create(
                    new Uri(@<API call to test connection>));
            Request.ContentType = "application/json";
            Request.Method = "Get";
            Request.Proxy = null;
            Request.Timeout = 5000;
            Request.Headers.Add("Authorization", "Bearer" + result.AccessToken);
  • Since stack overflow wont let me post more than two links, because I dont have enough reputation points. here is another link that I have used. https://blog.xamarin.com/put-adal-xamarin-forms/ – Reid Williams Mar 29 '17 at 13:44
  • Can you please try with ADAL.NET 3.17. We released it today. – Jean-Marc Prieur Oct 04 '17 at 04:39

3 Answers3

0

When you install the ADAL library from Nuget, Nuget should install two separate DLLs into each project of your Xamarin solution. One with the namespace Microsoft.IdentityModel.Clients.ActiveDirectory and one with Microsoft.IdentityModel.Clients.ActiveDirectory.Platform. The former is most of the logic for the library, while the latter is platform-specific logic for each target platform (iOS, Android, etc). Make sure that after installing Nuget, both packages are there in each project's dependencies. To ensure that Nuget installs the correct package, make sure each project targets the appropriate platform in the project properties/settings.

If you're saying that the DLLs are installed correctly but are not being picked up at runttime, I'm afraid I don't have an answer for you.

dstrockis
  • 1,173
  • 5
  • 6
0

In the appdelegate I had to instantiate a static method to register the ADAL dll. This resolved the issue.

 PlatformParameters pp = new PlatformParameters(Window.RootViewController);
0

Below stack url will help The located assembly's manifest definition does not match the assembly reference

In my case I have Microsoft.IdentityModel.Clients.ActiveDirectory with version 3.16.1 I uninstall this version and I again installed 3.16.0. And my problem is resolved.

Also you can have the look into your bindingRedirect.

Ashutosh B Bodake
  • 1,304
  • 1
  • 19
  • 31