MethodAccessException:方法 X 尝试访问 Dynamics 365 Plugin On Prem 中的方法 Y 失败
当我尝试在 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
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.
Anyone had the same issue? This same plugin works in .NET 4.5.2 but fails in 4.6.2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我们设法找到了解决方案,问题是 ILMerge 包含所有 System.*.dll,请阅读此 stackoverflow 答案 https:// /stackoverflow.com/a/67334636/2059998
因此,在 .NET 项目文件中添加 ILMerge 行
解决了该问题,这可确保在以下情况下不包含文件:运行 ILMergeWe 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
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