CRM Object Retrieval - Error: Unable to overlay an object of type "Microsoft.Xrm.Sdk.Entity" on type "CRMEntities.List"

I created objects from CRM as follows:

CrmSvcUtil.exe /url:http://<servername>/<organizationname>/XRMServices/2011/Organization.svc /out:<outputfilename>.cs /username:<username> /password:<password> /domain:<domainname> /namespace:CRMEntities /serviceContextName:XrmServiceContext 

For serviceContextName, I set XrmServiceContext . I want to get some object from CRM using the following code:

 var context = new XrmServiceContext(myorgserv); var marketingList = context.ListSet.Where(item => item.Id == new Guid("SOME GUID")); 

And I get the error message:

 Message "Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'CRMEntities.List'." 

After "add to watch", I saw that each set of entities in the context has the same message. What did I miss?

+6
source share
1 answer

The problem is resolved. After initializing OrganizationServiceProxy , I have to call the EnableProxyTypes Method .

 OrganizationServiceProxy orgserv; ClientCredentials clientCreds = new ClientCredentials(); clientCreds.Windows.ClientCredential.UserName = username; clientCreds.Windows.ClientCredential.Password = password; clientCreds.Windows.ClientCredential.Domain = domain; IServiceConfiguration<IOrganizationService> orgConfigInfo = ServiceConfigurationFactory.CreateConfiguration<IOrganizationService>(orgServiceUri); orgserv = new OrganizationServiceProxy(orgConfigInfo, clientCreds); orgserv.EnableProxyTypes(); 

Key things: orgserv.EnableProxyTypes ();

+16
source

Source: https://habr.com/ru/post/909753/


All Articles