locked
CRM 2011:Unable to load plug-in assembly RRS feed

  • Question

  • Hello,

    I was trying to update plugin by running plugin registration tool. there is no issue when I select 'Database' in step #4, but when I switch to 'Disk', it throws me error message like:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Unable to load plug-in assembly.
    Detail: <OrganizationServiceFault xmlns="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
      <ErrorCode>-2147204719</ErrorCode>
      <ErrorDetails xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
      <Message>Unable to load plug-in assembly.</Message>
      <Timestamp>2013-07-10T15:18:27.4402496Z</Timestamp>
      <InnerFault>
        <ErrorCode>-2147204719</ErrorCode>
        <ErrorDetails xmlns:a="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
        <Message>Unable to load plug-in assembly.</Message>
        <Timestamp>2013-07-10T15:18:27.4402496Z</Timestamp>
        <InnerFault i:nil="true" />
        <TraceText i:nil="true" />
      </InnerFault>
      <TraceText i:nil="true" />
    </OrganizationServiceFault>

    Server stack trace: 
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

    Exception rethrown at [0]: 
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at Microsoft.Xrm.Sdk.IOrganizationService.Update(Entity entity)
       at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.UpdateCore(Entity entity)
       at Microsoft.Crm.Tools.PluginRegistration.RegistrationHelper.UpdateAssembly(CrmOrganization org, String pathToAssembly, CrmPluginAssembly assembly, PluginType[] type)
       at Microsoft.Crm.Tools.PluginRegistration.PluginRegistrationForm.btnRegister_Click(Object sender, EventArgs e)

    So my question is:

    1. If I want to debug plugin using remote debugger, do I have to run plugin registration tool in 'Disk' mode? or it should be OK in 'Database' mode?

    2. If it's OK in 'Database' mode, since there is no problem to run plugin registration tool in 'Database' mode, I copy all PDB and DLL under CRM server\bin\assembly folder, and run remote debugger, but it doesn't stop at any breakpoints. In this case, the PDB and DLL in CRM server should match with my VS source code, why it doesn't stop at breakpoints?

    3. By the way, if I need to check whether all reference put in GAC or not, where should I go to check(GAC location)? Should they be under windir\assembly or somewhere under CRMdir? where is the actual location need to be checked?

    Any ideas?

    Thanks.

    Wednesday, July 10, 2013 3:51 PM

Answers

  • Here are some more things to check:

    1. Are you having ILMerge generate the PDB file for the merged assembly?  It should be generated by default, but there is a  /ndebug flag that also controls this.
    2. Are all of the assemblies and PDB files used as input to ILMerge in the same folder when generating the merged assembly?
    3. Your plugin is synchronous, but are you specifically unselecting sandbox mode when registering the plugin assembly?  If not, a synchronous plugin will still execute in a sandbox service process.
    4. Are you attaching to the correct w3wp.exe process?  If there are multiple I usually just attach to all of them, however, you can use IIS to determine the process ID of the processes for each application pool.

    Basically, I think your issue is either the PDB file and merged assembly created by ILMerge or an issue with attaching to the incorrect process.  You should only need to register the merged assembly and copy the merged PDB file to the server.  The other assemblies are not necessary and should not even be loaded when the plugin assembly is loaded since the dependencies are available in the merged assembly.


    Nick

    • Marked as answer by howexg9 Thursday, July 11, 2013 4:56 PM
    Thursday, July 11, 2013 2:59 AM

All replies

  • To answer your questions:

    1. You can debug your plugin when using "Database" mode.
    2. You are correct that you need to copy the PDB files for the plugin to the server\bin\assembly folder.  Are you connecting to the correct process.  The process depends upon your plugin registration.  Synchronous plugins will use the CRM application pool process, asynchronous plugins will use the async service process, and sandboxed plugins will use a sandbox process.  It can be difficult sometimes to remote debug sandboxed plugins because CRM will spawn new sandbox processes and you may not be attached to the correct one.  Also, the sandbox process may not exist until you have run the plugin at least once.  My suggestion for debugging is to not use sandboxed mode.
    3. Technically, external references for a plugin are not supported, however, if you are in an on premise or hosted situation and not using a sandboxed plugin you could copy your references to the GAC.  The GAC directory is typically C:\Windows\assembly.  The supported way to do include references would be to use a tool like ILMerge to merge your external dependencies into a single assembly with your plugin code.



    Nick

    Wednesday, July 10, 2013 4:24 PM
  • Hello Nick,

    Very good point. Actually, we are using ILMerge for our plugin. Here comes my another question: Do we only need copy Merged PDB to CRM\server\bin, or we still need to copy all single plugin PDB to there? When we update plugin using plugin registration tool, do we only need update merged plugin, or we need to update all single plugin separately?

    Back to my previous question, our plugin is synchronous, so we attach to w3wp.exe, we never use sandbox process. In order to debug plugin, do we still need to put merged dll under GAC, or just put under CRM\server\bin? In your experience, what else can cause the debug doesn't stop at breakpoints? My problem now is it just can stop at any breakpoints.

    Thanks.

    Wednesday, July 10, 2013 7:32 PM
  • Here are some more things to check:

    1. Are you having ILMerge generate the PDB file for the merged assembly?  It should be generated by default, but there is a  /ndebug flag that also controls this.
    2. Are all of the assemblies and PDB files used as input to ILMerge in the same folder when generating the merged assembly?
    3. Your plugin is synchronous, but are you specifically unselecting sandbox mode when registering the plugin assembly?  If not, a synchronous plugin will still execute in a sandbox service process.
    4. Are you attaching to the correct w3wp.exe process?  If there are multiple I usually just attach to all of them, however, you can use IIS to determine the process ID of the processes for each application pool.

    Basically, I think your issue is either the PDB file and merged assembly created by ILMerge or an issue with attaching to the incorrect process.  You should only need to register the merged assembly and copy the merged PDB file to the server.  The other assemblies are not necessary and should not even be loaded when the plugin assembly is loaded since the dependencies are available in the merged assembly.


    Nick

    • Marked as answer by howexg9 Thursday, July 11, 2013 4:56 PM
    Thursday, July 11, 2013 2:59 AM
  • Thanks, Nick. I'll double check.
    Thursday, July 11, 2013 4:56 PM