Search code examples
debuggingpluginsmicrosoft-dynamics

Debugging a Plugin throws "Could not load type 'Microsoft.Xrm.Sdk.IPluginExecutionContext4' from assembly 'Microsoft.Xrm.Sdk"


I just want to debug a plugin via the PluginRegistrationTool.

I have just updated the plugin with the latest version.

So the deployed plugin and the code are in sync. When I start debugging (Attach VS to PluginRegistrationTool and start execution) I get the following error:

Unhandled Exception: System.TypeLoadException: Could not load type 'Microsoft.Xrm.Sdk.IPluginExecutionContext4' from assembly 'Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
   at PluginProfiler.Plugins.ServiceWrappers.ExecutionContextWrapper.Deserialize(OperationType operation, String serializedValue)
   at PluginProfiler.Library.AppDomainProxy.Execute(ProfilerExecutionConfiguration configuration, ProfilerExecutionReport report)
   at PluginProfiler.Library.AppDomainProxy.Execute(ProfilerExecutionConfiguration configuration, ProfilerExecutionReport report)
   at PluginProfiler.Library.ProfilerExecutionEngine.Execute(ProfilerExecutionConfiguration configuration)
   at PluginProfiler.Library.ProfilerExecutionUtility.Execute(PluginPermissions permissions, ProfilerExecutionConfiguration configuration)
   at PluginProfiler.Library.ProfilerExecutionUtility.Execute(PluginPermissions permissions, OperationConfiguration operation, ProfilerReportingConfiguration reporting, CrmServiceClient administratorProxy, ITracingService tracing, ILogger pluginILoggerService)
   at Microsoft.Crm.Tools.DebugPlugin.DebugPluginViewModel.btnExecutionClicked()

I'm confused but does anybody have an idea why it references IPluginExecutionContext4??!

Nowhere in the project IPluginExecutionContext4 is referenced and the project builds without problems.

Any help is highly appreciated!


Solution

  • I had the same error message (IPluginExecutionContext4 exception) and found I was using an older debug Plug-in trace message from several months ago to hook to Visual Studio.

    I went into the PlugIn registration tools (a 2022 version in my case) and ran as administrator also. I uninstalled and reinstalled the PlugIn Profiler from the toolbar, then generated a new exception plug in trace (persisted to CRM) for my entity record. After that my code started working.

    https://learn.microsoft.com/en-us/power-apps/developer/data-platform/tutorial-debug-plug-in?tabs=prt