Plugin Issue troubleshoot : Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'CRM.Sales.Model.EarlyBound.t_accountteam'.

 Issue : Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'CRM. Sales. Model. EarlyBound .t_accountteam'.

During the Plugin development, t_accountteam early bound class was unable to type cast into Xrm.sdk.Entity during the runtime.

Resolution :

On the deep dive on this issue, use of the early bound in the C# Code, it needs to call  EnableProxyTypes method in the OrganizationServiceProxy.

Example :


string orgUrl = "https://xxxxxxxx/XRMServices/2011/Organization.svc";
            IOrganizationService _service = null;
            if (orgUrl != null)
            {
                Uri OrganizationUri = new Uri(orgUrl);
                var credentials = new ClientCredentials();
                credentials.Windows.ClientCredential = (NetworkCredential)CredentialCache.DefaultCredentials;
                System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, null, credentials, null);
               serviceProxy.EnableProxyTypes();
                int hrs = 6;
                int min = 6;
                serviceProxy.Timeout = new TimeSpan(hrs, min, 0);
                _service = (IOrganizationService)serviceProxy;            

            }

Comments

Popular posts from this blog

PCF vs. Web Resources: Choosing the Right Extensibility Tool for Dataverse

Is Debt Prosperity or Trap?

Exam PL-400: Microsoft Power Platform Developer