Posted on 21. December 2017

Method not found: '!!0[] System.Array.Empty()'.

I recently found an issue with Dynamics 365 Version 9 where a call to ITracingService.Trace(message) from inside a plugin caused the following exception:

System.MissingMethodException: Method not found: '!!0[] System.Array.Empty()'

Or

System.MissingMethodException: Method not found:
'System.String System.String.Format(System.IFormatProvider, System.String, System.Object)'.

 

I simply needed to replace it with TracingService.Trace(message,null);

Hope this helps!

Posted on 20. December 2017

OAuth Server to Server Application User Authentication

Recently I've been getting asked a great deal about how to perform non-interactive authentication with the Dynamics 365 WebApi in a server to server authentication scenario. The most common scenario is that you have an external server application that needs to access the Dynamics 365 WebApi.

The good news is that it's easy using Application Users. Here is a short video showing you how.

https://www.youtube.com/watch?v=Td7Bk3IXJ9s

The code in the video is as follows:

public static async Task Auth()
{
    string api = "https://org.crm11.dynamics.com/api/data/v9.0";

    AuthenticationParameters ap = AuthenticationParameters.CreateFromResourceUrlAsync(
                new Uri(api)).Result;

    var creds = new ClientCredential("ApplicationID", "ClientSecret");

    AuthenticationContext authContext = new AuthenticationContext(ap.Authority);
    var token = authContext.AcquireTokenAsync(ap.Resource, creds).Result.AccessToken;

    using (HttpClient httpClient = new HttpClient())
    {
        httpClient.Timeout = new TimeSpan(0, 2, 0);
        httpClient.DefaultRequestHeaders.Authorization =
            new AuthenticationHeaderValue("Bearer", token);

        HttpResponseMessage response = await httpClient.GetAsync(api + "/contacts?$top=1");
    }
}


 

Hope this helps!