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

Decode and Fix: “This Data Type is Unsupported for Evaluation” in Power Apps

Effective Strategies for Debugging Plugins in Dynamics CRM

Dynamics 365 Plugin Life Cycle Simplified for Business Users and Developers

Connecting the Dots: FetchXML and Web API Integration in Dataverse

Step-by-Step Guide to Building Custom APIs in Dataverse

Stop Struggling with Plugins: Learn IOrganizationService the Smart Way

Managing Parallel Development and Hotfixes in Dataverse Like a Pro

Bridging Dataverse and External APIs with Custom API

How Every Plugin Action Travels Through Request, Service, and the Pipeline

Model-Driven Apps Command Bar: A Guide to PrimaryControl and SelectedControl