-1

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

Juan Stoppa
  • 460
  • 1
  • 4
  • 15
  • Does this issue occur on a particular machine? Did you check the platform target of your assembly (Any CPU/x86/c64). On that machine does your component work when executed from a console app e.g.? – Henk van Boeijen Apr 01 '22 at 06:04
  • target framework is 4.6.2. I’ve got other orgs running plugins in 4.6.2 in the same machine with no problem. The only issue seems to be this particular plug-in that makes an external API call, it works if target is 4.5.2 but it fails in 4.6.2. I haven’t tried running it in a console app, We do have other web services in the same machine using 4.6.2 that make use of System.Net.Http – Juan Stoppa Apr 01 '22 at 06:27
  • Did you check the platform target of your assembly (Any CPU/x86/x64)? – Henk van Boeijen Apr 01 '22 at 15:18
  • target framework is 4.6.2 and any CPU. In any case, the issue was that we were including the System.*.dll, added an answer with the details – Juan Stoppa Apr 02 '22 at 19:07

1 Answers1

0

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>
Juan Stoppa
  • 460
  • 1
  • 4
  • 15