[CRM 2011] Early bound types and plugins

Have you tried to use early bound types in plugins? After run crmsvcutil to generate the early bound types, you probably want to use them in your plugins. If the generated code is in the same assembly that the plugins, you won’t get any problem.

image

However, in a medium-big project, you may want to separate common functionality, as business processes or entity wrappers, from the rest.

image

How are you going to deploy that Common library? Either you can put it in the GAC or merge it with the Plugins assembly. However, as it is, you will get an “Unexpected error” the first time you try to use the IOrganizationService with early bound types inside of your plugins. Example:

public class PreCreateContact : BasePlugin
{
   protected override void ExecutePlugin(IOrganizationService service, ITracingService tracingService)
   {
       Task newTask = new Task();
       newTask.Subject = "Testing";
       service.Create(newTask); //Here you will get the error
   }

}

To avoid this exception, you should add the next line to AssemblyInfo.cs in your Plugin project

[assembly: Microsoft.Xrm.Sdk.Client.ProxyTypesAssemblyAttribute()]
Advertisements

Posted on June 13, 2011, in CRM, CRM 2011 and tagged , . Bookmark the permalink. 1 Comment.

  1. It’s always great to read stuff from the master of coding …

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: