0

所以我在preLeadUpdate上写了一个插件,调用动态webapi。当从 Visual Studio 对 fe 开发环境运行单元测试时,它工作正常,但是在将插件部署到 dev-dynamics 实例时,我在执行时收到以下错误:

System.MethodAccessException:尝试通过方法“System.Net.Http.HttpClientHandler.Dispose(Boolean)”访问方法“System.Net.ServicePointManager.CloseConnectionGroups(System.String)”失败

在堆栈跟踪中,我看到它在以下方法中执行“var response = authClient.PostAsync(url, ....)”行时失败:

 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<string, string>("resource", resource),
                            new KeyValuePair<string, string>("client_id", clientId),
                            new KeyValuePair<string, string>("client_secret", secret),
                            new KeyValuePair<string, string>("grant_type", "client_credentials")
            })).Result;

        if (response.IsSuccessStatusCode)
        {
            var result = response.Content.ReadAsStringAsync();
            token = JsonConvert.DeserializeObject<AzureTokenResponse>(result.Result);
        }
        else
        {
            throw new Exception("Could not get token for Azure");
        }

        return token;
    }

在对错误进行一些谷歌搜索后,我几乎觉得好像有一些引用的 dll 不是插件程序集的一部分,而是可能从 dev-webserver 上的 GAC 引用。也许该 dll 是服务器上某些方法不可访问的旧版本(可能未声明为“公共”)

我已经确保对 System.Net.Http 的所有引用都是“复制本地 = true”,但这似乎没有帮助。

所以我有点绝望并愿意接受建议。

4

0 回答 0