CRM 2011 Plugin And Early Bound Entities

By | March 16, 2012

In my first crm 2011 project I struggled a little bit with the early binding functionality. When you generate the entities with CrmSvcUtil and place the entities in the plugin project everything works fine. But when you seperate the entities from you plugin logic in a other dll, early binding won’t work.
The first solution I found in the internet was this here. Referencing following libraries in the plugin project:


And then setting the ProxyTypesAssembly attribute.

(Microsoft.Crm.Extensibility.PipelineExecutionContext)context).ProxyTypesAssembly = typeof(AnyGeneratedEntity).Assembly;

This works fine. But when your plugin runs asynchronous the code above will fail. Because the context isn’t a PipelineExecutionContext object. Context in async plugins are of type AsyncExecutionContext. And this class is placed in the AsyncCrmService.exe (yes! EXE). This means, you have to reference this exe file and cast the context to set the ProxyTypesAssembly.

(Microsoft.Crm.......AsyncExecutionContext)context).ProxyTypesAssembly = typeof(AnyGeneratedEntity).Assembly;

A other solution is to set the ProxyTypesAssembly with reflection. It works but isn’t really a nice solution too.

Both solutions are not very nice. Because you have to reference CRM 2011 dlls,exes which are not really meant for creating plugins, or you have to develop type unsafe.

My solution is
Afer inspecting the AsyncExecutionContext class with ILSpy I found out, that every context implements the interface IProxyTypesAssemblyProvider. And this interface is placed in the xrm sdk 😉

Now, the solution is simple. Remove any CRM 2011 dlls,exes like ObjectModel, Platform.Server or CrmAsyncService.exe and set the ProxyTypesAssembly property like here:

(IProxyTypesAssemblyProvider)context).ProxyTypesAssembly = typeof(AnyGeneratedEntity).Assembly;

(The interface is placed in the xrm sdk dll which you need for plugin development.)

This will work for every other context which supports early binding.

7 thoughts on “CRM 2011 Plugin And Early Bound Entities

  1. Erik K. Aarslew-Jensen

    You stated that the IProxyTypesAssembly interface is included in the xrm sdk dll, but when including the “microsoft.xrm.sdk.dll” to my project, it doesn’t recognize this interface.

    Which version of the SDK are you using? …or are you in fact talking about the IProxyTypesAssemblyProvider interface?

  2. admin Post author

    Hi. Yes you’re right. I’m sorry. The name of the interface is “IProxyTypesAssemblyProvider” and the property is “ProxyTypesAssembly”.

    Thanks. I’ll correct my post.

  3. Denis

    This is amazing! Do you realize how much work this is saving people who find this post? This should be written in bold, red letters on Microsoft’s homepage!

    Thank you, thank you, thank you!

  4. admin Post author

    Never tried before. Does the custom workflow context doesn’t implement the Interface “IProxyTypesAssemblyProvider”?

  5. dmicic

    Well.. at this point in time probably not. CRM 2013 was quite new. I could not find any solution in the Internet.

Leave a Reply

Your email address will not be published. Required fields are marked *

× three = 6