It’s second time that I have this error but everytime I forgot the solution and I need to search again…. 🙂 Now I want to save the solution here on my blog.
So I ran into a very tricky error when building a custom tool to register CRM 2011 Plug-ins. I wouldn’t be surprised if other people run into the same issue when registering plug-ins programmatically. And its such a strange problem I thought it deserved an explanation.
Here is the exception I got when retrieving a list of records from CRM:
<strong>A proxy type with the name account has been defined by another assembly. Current type: Plugins1.Entities.Account, App_Code.zzq-u5xe, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null, Existing type: Plugins1.Entities.Account, vender portal, Version=22.214.171.124, Culture=neutral, PublicKeyToken=null Parameter name: account</strong>
I trace the problem what it is? It is actually problem from Organization Service i used,It gets definition of account entity definition from two assembly and confuse to process which assembly should be executed for actual objects.
Issue resolved by specify assembly for execution or creating objects for entities:
just have to add a new ProxyTypesBehavior:
ClientCredentials credentials = new ClientCredentials(); credentials.Windows.ClientCredential = new NetworkCredential(username, password, domain); credentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation; IServiceConfiguration<IOrganizationService> orgConfigInfo = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(new Uri(@"[...]/XRMServices/2011/Organization.svc")); OrganizationServiceProxy client = new OrganizationServiceProxy(orgConfigInfo, credentials); <strong>client.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior(Assembly.GetExecutingAssembly()));</strong>