title: System.TypeInitializationException: The type initializer for 'Microsoft.IdentityModel.Clients.ActiveDirectory.Authenticator' threw an exception
body: <p>I'm attempting to perform S2S authentication from a Dynamics 365 plugin, unsuccessfully so far. The following exception occurs:</p>
  
  <pre><code>System.TypeInitializationException: The type initializer for 'Microsoft.IdentityModel.Clients.ActiveDirectory.Authenticator' threw an exception
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>var clientCreds = new ClientCredential(clientId, secret);
  
  AuthenticationContext authContext = new AuthenticationContext(authorityUri);
  AuthenticationResult authResult = authContext.AcquireTokenAsync(resource, clientCreds).GetAwaiter().GetResult();
  </code></pre>
  
  <p>We are using the following packages:</p>
  
  <p>
              </p>
  
  <p>The same code works in a console app. Any help/suggestions are very appreciated.</p>