Search code examples
c#microsoft-dynamics.net-4.6.2ilrepack

Debug ILRepack merged plugin assembly from Plugin Registration tool


I'm trying to debug plugin assembly that been merged via ILRepack, but Plugin Registration tool's Replay Plug-in Execution throws an error related to System.Text.Json: Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Operation could destabilize the runtime.

Merging command looks like this:

<Target Name="ILRepack" AfterTargets="Build">
    <Message Text="ILRepack is running..." />
    <ItemGroup>
        <ILRepackPackage Include="..\packages\ILRepack.2.0.18\tools\ILRepack.exe" />
    </ItemGroup>
    <Error Condition="!Exists(@(ILRepackPackage->'%(FullPath)'))" Text="You are trying to use the ILRepack package, but it is not installed or at the correct location." />
    <Exec Command="@(ILRepackPackage->'%(FullPath)') /out:$(OutputPath)Merged\$(AssemblyName).dll $(OutputPath)$(AssemblyName).dll <...AND ALL OTHER ASSEMBLIES> /parallel /wildcards /target:library /keyfile:NPDKey.snk" />
</Target>

Code execution works fine in Dynamics 365 CE (online), only Plugin replay is throwing an error.

I tried:

  1. Debug non-merged assembly, that did not help.
  2. Debug non-signed merged assembly, that did not help.
  3. To not use ILRepack, but that made it even worse.
  4. To use different merge tools like ILRepect.Lib.MSBuild.Task or ILRepack.MSBuild.Task but those have same effect.

Here's some code that throws actual error:

var data = System.Text.Json.JsonSerializer.Serialize(object);

Version of System.Text.Json is 6.0.5


Solution

  • After doing a lot more of research I found out that I can debug ILRepack merged assembly by the Replay Plug-in Execution feature in Plugin Registration tool. However in Settings tab, Isolation Mode must be selected as "none", see image below.

    Replay Plug-in Execution Settings tab