【问题标题】:CRM Retrieve entity - Error: Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'CRMEntities.List'CRM 检索实体 - 错误:无法将“Microsoft.Xrm.Sdk.Entity”类型的对象转换为“CRMEntities.List”类型
【发布时间】:2012-03-20 02:41:17
【问题描述】:

我像这样从 CRM 生成实体:

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

对于 serviceContextName,我设置了 XrmServiceContext。 我想使用下一个代码从 CRM 中检索一些实体:

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

我得到了错误:

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

在“添加到观看”之后,我看到上下文中的每组实体都有相同的消息。 我错过了什么?

【问题讨论】:

    标签: c# dynamics-crm-2011 early-binding


    【解决方案1】:

    问题解决了。初始化OrganizationServiceProxy后,我必须调用 EnableProxyTypes 方法。

    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();
    

    关键是:orgserv.EnableProxyTypes();

    【讨论】:

    • 谢谢!把我的头撞在墙上,效果很好!
    猜你喜欢
    • 2022-01-14
    • 2018-03-22
    • 2023-04-03
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多