MethodAccessException:方法 X 尝试访问 Dynamics 365 Plugin On Prem 中的方法 Y 失败

发布于 2025-01-18 06:34:26 字数 1674 浏览 0 评论 0原文

当我尝试在 Dynamics 365 v9.1 中将插件从 .NET 版本 4.5.2 移动到 4.6.2 时,出现以下错误

 System.AggregateException: One or more errors occurred. ---> System.MethodAccessException: Attempt by method 'System.Net.Http.WinHttpResponseParser.GetReasonPhrase(System.Net.HttpStatusCode, Char[], Int32)' to access method 'System.Net.HttpStatusDescription.Get(System.Net.HttpStatusCode)' failed.
   at System.Net.Http.WinHttpResponseParser.GetReasonPhrase(HttpStatusCode statusCode, Char[] buffer, Int32 bufferLength)
   at System.Net.Http.WinHttpResponseParser.CreateResponseMessage(WinHttpRequestState state, Boolean doManualDecompressionCheck)
   at System.Net.Http.WinHttpHandler.<StartRequest>d__103.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.Http.HttpClient.<FinishSendAsync>d__58.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)

我可以部署该插件并且工作正常。当插件尝试对我们从插件调用的外部 API 进行 Web 服务调用时,我收到上述错误

该插件未处于沙盒模式,并且已在数据库中注册 输入图片这里的描述

我用 JustDecompile 打开了插件程序集,并跟踪了加载 System.dll 中的方法的问题,看起来它正在尝试从 GAC 加载它,但失败了。

输入图片此处描述

有人遇到过同样的问题吗?这个插件在 .NET 4.5.2 中工作,但在 4.6.2 中失败

I'm getting the error below when trying to move a plugin from version .NET version 4.5.2 to 4.6.2 in Dynamics 365 v9.1

 System.AggregateException: One or more errors occurred. ---> System.MethodAccessException: Attempt by method 'System.Net.Http.WinHttpResponseParser.GetReasonPhrase(System.Net.HttpStatusCode, Char[], Int32)' to access method 'System.Net.HttpStatusDescription.Get(System.Net.HttpStatusCode)' failed.
   at System.Net.Http.WinHttpResponseParser.GetReasonPhrase(HttpStatusCode statusCode, Char[] buffer, Int32 bufferLength)
   at System.Net.Http.WinHttpResponseParser.CreateResponseMessage(WinHttpRequestState state, Boolean doManualDecompressionCheck)
   at System.Net.Http.WinHttpHandler.<StartRequest>d__103.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.Http.HttpClient.<FinishSendAsync>d__58.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)

I can deploy the plugin and it works fine. I'm getting the error above when the plugin attempts to make a web service call to an external API we call from the plugin

The plugin is NOT in sandbox mode and it's registered in the database
enter image description here

I opened the plugin assembly with JustDecompile and tracked down the issue to loading a method in System.dll, it looks like it's trying to load it from the GAC and fails.

enter image description here

Anyone had the same issue? This same plugin works in .NET 4.5.2 but fails in 4.6.2

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝颜夕 2025-01-25 06:34:26

我们设法找到了解决方案,问题是 ILMerge 包含所有 System.*.dll,请阅读此 stackoverflow 答案 https:// /stackoverflow.com/a/67334636/2059998

您可能希望避免合并 .NET Framework 中的任何内容(我假设 System.Memory 和 System.Threading.Tasks 等库就是这样)。

因此,在 .NET 项目文件中添加 ILMerge 行 解决了该问题,这可确保在以下情况下不包含文件:运行 ILMerge

<Target Name="ILMerge" AfterTargets="Build">
<ItemGroup>
    <Files Include="$(TargetDir)*.dll" />
    <Files Remove="$(TargetDir)$(AssemblyName).dll" /> 
    <Files Remove="$(TargetDir)AntiXSSLibrary.dll" />
    <Files Remove="$(TargetDir)Microsoft*.dll" />
    <Files Remove="$(TargetDir)System*.dll" />
</ItemGroup>

We managed to find a solution for this, the problem was ILMerge was including all System.*.dll, reading in this stackoverflow answer https://stackoverflow.com/a/67334636/2059998

You might want to avoid merging anything that's part of the .NET Framework (which I assume that libraries like System.Memory and System.Threading.Tasks are).

So adding the line <Files Remove="$(TargetDir)System*.dll" /> for ILMerge in the .NET project file fixed the issue, this makes sure the files are not included when running ILMerge

<Target Name="ILMerge" AfterTargets="Build">
<ItemGroup>
    <Files Include="$(TargetDir)*.dll" />
    <Files Remove="$(TargetDir)$(AssemblyName).dll" /> 
    <Files Remove="$(TargetDir)AntiXSSLibrary.dll" />
    <Files Remove="$(TargetDir)Microsoft*.dll" />
    <Files Remove="$(TargetDir)System*.dll" />
</ItemGroup>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文