1

I'm developing a plugin for CRM 2011.

I have a generic base class for all my plugins:

public abstract class Plugin_Base<T> : IPlugin
    where T : Entity, new()
{
    void IPlugin.Execute(IServiceProvider serviceProvider)
    {
    }
}

However when I pass an early bound entity as a parameter, my step registration fails for the plugin: 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 the plugin type: My.Namespace.AccountPlugin

If I simply change the generic parameter any other class type (and remove the constraint for it to be an Entity), the step registration succeeds.

Why is this happening, is there a way around this?

Bitfiddler
  • 3,942
  • 7
  • 36
  • 51
  • What's your project setup here? – James Wood Dec 06 '15 at 00:08
  • Simple class library project. – Bitfiddler Dec 06 '15 at 00:51
  • I guess I should add that I have a second class library for the generated early bound classes and the plugin project uses MSBuild.ILMerge.Task nuget package to bundle everything up into one dll. I also use custom naming and the /codecustomization switch when generating my early bound classes. – Bitfiddler Dec 06 '15 at 01:09
  • I bundle microsoft.xrm.client and microsoft.xrm.sdk.deployment in with my plugin dll. – Bitfiddler Dec 06 '15 at 01:12
  • Hmm, not dealt with that exact situation. `Unable to load the plugin type` typically means you are trying to use something which is missing from your assembly or CRM. I can suggest; 1. Not including `xrm` assemblies, pretty sure they are not required. 2. Try making a simple project with the source for `Plugin_Base` and `AccountPlugin` inside, to try and narrow down the issue. I.e. if that works probably an issue in your ILMerge. – James Wood Dec 06 '15 at 20:03
  • @BitFiddler if you are using ILMerge, then make sure that `xrm assemblies` that you add to plugin have `Copy Local` false in the `Properties` – Dot_NET Pro Dec 07 '15 at 08:15
  • If I don't include those xrm assemblies the plugin won't work at all. My early bound entities context needs them (see codecustomization using Microsoft.Xrm.Client.CodeGeneration.CodeCustomization). I tried keeping all the code the same except I changed the generic constraints to accept any newable class and commented out the code that needs an Entity. I kept everything else the same (same references etc.) and it works. Change it back to use early bound entities, exception. – Bitfiddler Dec 07 '15 at 22:18
  • Does your assembly have the `[assembly: Microsoft.Xrm.Sdk.Client.ProxyTypesAssembly]` attribute? It should be added to the AssemblyInfo.cs. – Henk van Boeijen Dec 09 '15 at 14:31
  • Yes. Learned that the hard way :-S But thank you for helping. – Bitfiddler Dec 09 '15 at 20:17

0 Answers0