A proxy type with the name account has been defined by another assembly - CRM 365 Earyl-bound classes

132 views Asked by At

I'm currently working on connecting to two CRMs (2011 on-premise and 365 online) within a single console application. Everything works fine until I attempt to use two early-bound class libraries simultaneously, at which point I encounter an error with the title

This is my code:

using (OrganizationServiceProxy crmProxy = CrmHelper.GetServiceProxy(config.CrmUri, _syncU[1], config.SerwisUserPassword, _syncU[0]))
{
   CRM2011.Account accCRM = crmProxy.Retrieve(CRM2011.Account.EntityLogicalName, Guid.Parse("C67CF43C-D6AE-ED11-A4A2-00155D00E457"), new ColumnSet(true)).ToEntity<CRM2011.Account>();
   name = accCRM.Name;
}
string connectionString = "AuthType=Office365;Username = username;Url = https://****.api.crm4.dynamics.com;Password = password;";
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
CrmServiceClient conn = new CrmServiceClient(connectionString);
CRM365.Account acc = new CRM365.Account();
acc.Name = name;
conn.Create(acc);

And when I invoke the Create method, I receive this error.

If I invoke it this way, everything goes through correctly, but it's inconvenient and prone to errors.

Entity acc = new Entity("account");
acc.Attributes.Add("name", name);
conn.Create(acc);

I have already tried all the methods I found on the internet, including this, but without success:

proxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior(Assembly.GetExecutingAssembly()));

I would be grateful for any assistance.

2

There are 2 answers

1
Daryl On BEST ANSWER

This is an issue I've had since day 1 with the CRM proxy resolver. It will attempt to automatically lookup the class type for the entity that you're retrieving/creating. A work around is to remove the [assembly: Microsoft.Xrm.Sdk.Client.ProxyTypesAssemblyAttribute()] attribute from one of your early bound assemblies.

0
MattB On

a bit more explanation, the proxy resolver is trying to resolve the class name ‘account’ map a response back from the server. as the sever is unaware of namespaces defined in your local client, when 2 instances of ‘account’ exist in different namespaces in your client, the resolver cannot determine which instance to use. In that case it fails vs randomly choosing one to cast it too.

That is what causes this error.

Daryl’s recommendation is the correct fix in this case