zoukankan      html  css  js  c++  java
  • Dynamic CRM 2013学习笔记(三十)Linq使用报错 A proxy type with the name account has been defined by another assembly

    在CRM中使用linq时,有时会报这个错误:

    A proxy type with the name account has been defined by another assembly.

    Current type: Account, MyAssembly, Version=1.0.0.4, Culture=neutral, PublicKeyToken=be9afbacb707a086,

    Existing type: Account, CustomPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

    Parameter name: account”

    网上一搜索,有人说解决很简单:

    var connection = CrmConnection.Parse(connectionString);
    connection.ProxyTypesAssembly = Assembly.GetExecutingAssembly();

    再到项目里一看,发现就没有这个CrmConnection:

    Uri orgServiceUri = new Uri(CRMServiceUrl + "/XRMServices/2011/Organization.svc");
                ClientCredentials credentials = new ClientCredentials();
                if (CRMAuthenticationType == "AD")
                {
                    credentials.Windows.ClientCredential = new System.Net.NetworkCredential(CRMUserName, CRMUserPassword, CRMUserDomainName);
                }
                else if (CRMAuthenticationType == "ADFS")
                {
                    credentials.UserName.UserName = CRMUserDomainName + "\" + CRMUserName;
                    credentials.UserName.Password = CRMUserPassword;
                }
                OrganizationServiceProxy crmServiceProxy = new OrganizationServiceProxy(orgServiceUri, null, credentials, null);
                crmService = (IOrganizationService)crmServiceProxy;

    原来是用的OrganizationServiceProxy,于是把它改成OrganizationService,因为OrganizationService里面会用到这个CrmConnection:

    ClientCredentials credentials = new ClientCredentials();
    if (CRMAuthenticationType == "AD")
    {
        credentials.Windows.ClientCredential = new System.Net.NetworkCredential(CRMUserName, CRMUserPassword, CRMUserDomainName);
    }
    else if (CRMAuthenticationType == "ADFS")
    {
        credentials.UserName.UserName = CRMUserDomainName + "\" + CRMUserName;
        credentials.UserName.Password = CRMUserPassword;
    }
    string server = string.Format("Url={0};Domain={1};Username={2};Password={2}", CRMServiceUrl, CRMUserDomainName, CRMUserName, CRMUserPassword);
    var connection = CrmConnection.Parse(server);
    connection.ProxyTypesAssembly = Assembly.GetExecutingAssembly();
    connection.ClientCredentials = credentials;
    m_CrmService = new OrganizationService(connection);
    m_SvcContext = new ServiceContext(m_CrmService);

    改完后,就不报这个错了。

    Dynamic CRM 2013学习笔记 系列汇总 -- 持续更新中

  • 相关阅读:
    Linux中的文件夹的增删改查命令和文件的增删改查命令
    xshell开源软件
    2020090808redis之linux的gcc的升级安装(八)
    2020090807redis之windows安装(七)
    2020090806redis之理解(六)
    2020090805redis之nosql的四大分类(五)
    每个牛逼的人都有一段苦逼的岁月,但是只要像SB一样坚持,终将牛逼
    2020090804redis之数据库的搭建(四)
    2020090803redis之大数据3V+3高(三)
    2020090802redis之非关系 数据库nosql(二)
  • 原文地址:https://www.cnblogs.com/fengwenit/p/4253484.html
Copyright © 2011-2022 走看看