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.
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.