1

I'm attempting to perform S2S authentication from a Dynamics 365 plugin, unsuccessfully so far. The following exception occurs:

System.TypeInitializationException: The type initializer for 'Microsoft.IdentityModel.Clients.ActiveDirectory.Authenticator' threw an exception

My understanding is that the exception is thrown at the time when IdentityModel dll gets loaded, not even during runtime. However, if that matters, here is what we are doing in code:

var clientCreds = new ClientCredential(clientId, secret);

AuthenticationContext authContext = new AuthenticationContext(authorityUri);
AuthenticationResult authResult = authContext.AcquireTokenAsync(resource, clientCreds).GetAwaiter().GetResult();

We are using the following packages:

The same code works in a console app. Any help/suggestions are very appreciated.

Shalom Aleichem
  • 2,987
  • 2
  • 22
  • 34

1 Answers1

0

This might be because you are running in the sandbox. Whilst the MSDN doesn't explicity advise against this, it recommends you only connect to anonymous services.

Plug-in isolation, trusts, and statistics

Access to the file system, system event log, certain network protocols, registry, and more is prevented in the sandbox.

...

Sandboxed plug-ins and custom workflow activities can access the network through the HTTP and HTTPS protocols....The following web access restrictions apply to this sandbox capability.

  • Anonymous authentication is supported and recommended.
James Wood
  • 17,286
  • 4
  • 46
  • 89