Dynamic CRM 2013学习笔记(三十)Linq使用报错 A proxy type with the name account has been defined by another assembly
2023-09-11 14:19:00 时间
在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);
改完后,就不报这个错了。
相关文章
- vue—你必须知道的 js数据类型 前端学习 CSS 居中 事件委托和this 让js调试更简单—console AMD && CMD 模式识别课程笔记(一) web攻击 web安全之XSS JSONP && CORS css 定位 react小结
- opencv学习笔记(四)投影
- 机器学习笔记之集成学习(二)Bagging与随机森林
- PL/SQL学习笔记(三) ——PL/SQL代码编写规则
- Nexus学习笔记--安装使用教程
- SwiftUI进阶之 01 软件开发的核心是什么 (《代码大全》学习笔记)
- 算法复习笔记(一)算法基础知识
- Tensorflow2.0 入门与实战学习笔记(十四)-RNN循环卷积网络
- opencv/openmv学习笔记
- C++MFC编程笔记day01 MFC介绍、创建MFC程序和重写消息处理
- cocos2d-x 3.0学习游戏笔记的例子《卡塔防》第五步---开始建立游戏界面
- 学习笔记(56):Python实战编程-Menu
- 学习笔记(38):Python实战编程-窗体显示
- javascript 的学习笔记(第一天)
- Arduino学习笔记54
- 《RefineNet: Multi-Path Refinement Networks for High-Resolution Semantic Segmentation》论文笔记