More About This Website

All information is provided "AS IS" with no warranties, and confers no rights

Login
Powered by Squarespace
« CRM Client Extension Data Access Strategies | Main | Working with Field Level Security from a Plugin »
Thursday
May312012

Using Early Types across assemblies in plugins

It’s not uncommon for us to have are generated types in one assembly and have a plugin that uses the code that in another assembly.  When doing that CRM doesn’t do well with resolving the classes. 

To work around this you can give CRM a hint by setting the ProxyTypeAssembly.  To do this you must first get a reference to the IProxyTypeAssemblyProvider – we typically do this by casting the IOrganizationServiceFactory instance we get to that type and go from there.  Here’s an example of a helper method to get the Organization Service and setup the ProxyTypeAssembly prior to creation of the service instance.

public IOrganizationService CreateService(Guid? userID) 
{

            var factory = ServiceProvider.GetService(typeof(IOrganizationServiceFactory))
                        as IOrganizationServiceFactory;            
            var proxyProvider = factory as IProxyTypesAssemblyProvider;          
            proxyProvider.ProxyTypesAssembly = ProxyTypeAssembly;     

           return  factory.CreateOrganizationService(userID);            
}

ProxyTypeAssembly in this example would need to be the assembly that contains your generated classes.  Clearly I’ve stripped out any error handling and other good stuff from this method but you get the general idea.

EmailEmail Article to Friend

References (9)

References allow you to track sources for this article, as well as articles that were written in response to this article.
  • Response
    I have been looking in vain to find this subject, now I have found it! I will be following you, (dont worry I am not a stalker) but just wondering how often you update this webpage with new posts. Seems like a lot of crazy comments already, hope you will be ...
  • Response
    Thanks a ton..really helpful!!
  • Response
    Response: www.agtkuwait.com
    Once once more I believe you write some thing unique! I hope you will compose additional and soon , I love transha ha hauals!
  • Response
    This website is awesome. I constantly come across something new & different right here. Thank you for that data.
  • Response
    Response: BFASarQy
    - MrDave's (David Yack) CRM Blog! - Using Early Types across assemblies in plugins
  • Response
    - MrDave's (David Yack) CRM Blog! - Using Early Types across assemblies in plugins
  • Response
    Response: Hollister
  • Response
    Football is seriously 1 of the greatest sports in America. It has a key following.
  • Response
    Awesome Webpage, Stick to the great work. Thanks.

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.