So I wrote a plugin on preLeadUpdate that calls dynamics webapi. When running unit tests agains f.e the dev-environment from Visual Studio it works fine but when deploying the plugin to the dev-dynamics instance I get the following error when it executes:
System.MethodAccessException:
Attempt by method 'System.Net.Http.HttpClientHandler.Dispose(Boolean)' to access method 'System.Net.ServicePointManager.CloseConnectionGroups(System.String)' failed
In the stack trace I see that it fails when executing the line "var response = authClient.PostAsync(url, ....)" in the following method:
using (HttpClient authClient = new HttpClient()) { AzureTokenResponse token; string url = "https://login.microsoftonline.com/" tenantId "/oauth2/token"; var response = authClient.PostAsync(url, new FormUrlEncodedContent(new[] { new KeyValuePair("resource", resource), new KeyValuePair("client_id", clientId), new KeyValuePair("client_secret", secret), new KeyValuePair("grant_type", "client_credentials") })).Result; if (response.IsSuccessStatusCode) { var result = response.Content.ReadAsStringAsync(); token = JsonConvert.DeserializeObject(result.Result); } else { throw new Exception("Could not get token for Azure"); } return token; }
After some googling on the error I almost feel as if there is some referenced dll that is not part of the pluginassembly but instead maybe referenced from the GAC on the dev-webserver. And maybe that dll is of an older version on the server where some method is not accessible (maybe not declared as "public")
I've made sure that all the references to System.Net.Http are "copy local = true" but that doesn't seem to help.
So I'm getting a bit desperate and open for suggestions.