我正在尝试创建一个简单的 Dynamics CRM 插件,以使用 Microsoft 的 XRM 工具创建多个实体关联。我用这种方式实例化这个类:
public class PartnerPlugin : IPlugin
{
public static IOrganizationService staticservice;
string log = string.Empty;
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
CrmServiceClient crmService = new CrmServiceClient((OrganizationServiceProxy)serviceFactory.CreateOrganizationService(context.UserId));
...
}
}
这与我已经在 CRM 注册的另一个代码几乎相同,但这次它给了我这个错误:
[A]Microsoft.Xrm.Tooling.Connector.CrmWebSvc cannot be cast to [B]Microsoft.Xrm.Tooling.Connector.CrmWebSvc. Type A originates from 'plab_quote, Version=1.0.0.0, Culture=neutral, PublicKeyToken=567d876020387fa5' in the context 'LoadNeither' in a byte array. Type B originates from 'quotePartners, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4f3d8ebbe2fb8cfb' in the context 'LoadNeither' in a byte array. If you contact support, please provide the technical details.
问题是,经过大量测试后,我只添加了这 3 行代码 (IPluginExecutionContext context = (...) CreateOrganizationService(context.UserId))) 没事了。同样的错误。 我正在使用 Dynamics CRM 365
另一个奇怪的事情:我已经遇到了这个错误,但是,(我发誓)我只花了 5 分钟喝咖啡,当我回来重试时,错误就消失了。 我又尝试了一些咖啡,但没有效果。没有任何效果。
有人吗?有什么想法吗?
最佳答案
您的插件有两个字段,staticservice
和 log
。
这两个字段(静态字段和实例字段)都不是线程安全的。对于每个插件类-阶段-模式组合,系统都会创建一个用于多个最终并发事件的实例。
竞争条件会导致线程覆盖彼此的字段,从而导致意外结果。
关于c# - MS Dynamics CRM 插件错误 - [A]CrmWebSvc 无法转换为 [B]CrmWebSvc,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42092449/