Entité de récupération CRM - Erreur: impossible de lancer l'objet de type 'microsoft.xrm.sdk.entity' pour taper "Craprentities.list"

StackOverflow https://stackoverflow.com/questions/9518994

Question

J'ai généré des entités de crm comme ceci:

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

pour ServicecontextName I Set xrmservicecontext . Je souhaite récupérer une entité de la CRM à l'aide du code suivant:

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

Et je reçois une erreur:

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

Après "Ajouter à la montre", j'ai vu que chaque ensemble d'entités dans le contexte a le même message. Qu'as-je manqué?

Était-ce utile?

La solution

Problem solved. After initializing OrganizationServiceProxy, I have to call 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 thing is: orgserv.EnableProxyTypes();

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top