gpt4 book ai didi

dynamics-crm-2011 - 导致TypeLoad异常的CRM 2011在线实例的扩展方法

转载 作者:行者123 更新时间:2023-12-04 19:09:40 25 4
gpt4 key购买 nike

我正在为 CRM Online 试用租户上的客户编写插件(因此假设它有最新的补丁等)并且遇到了我以前从未见过的错误。一般来说,我总是使用以下几行的扩展方法,只是为了代码的清晰性:

public static void AddOrUpdate(this Entity e, string propertyName, object value)
{
if (e.Attributes.Contains(propertyName))
{
e.Attributes[propertyName] = value;
}
else
{
e.Attributes.Add(propertyName, value);
}
}

我认为没有什么有很大争议的吗?无论如何,如果我将类文件作为此客户端的插件的一部分包含在内,我会抛出以下错误:
Unhandled Exception: System.ServiceModel.FaultException`1
System.TypeLoadException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #9A0442A7

[foo.bar.Plugins: foo.bar.Plugins.TrackActivity]
[6ed535ec-c7a8-e211-858f-3c4a92dbdc37: foo.bar.Plugins.TrackActivity: Create of task]

没有包含任何跟踪,这表明插件甚至没有执行(即使第一行代码抛出异常!)。

我做了一些挖掘,似乎至少对于这个客户/实例:
- 如果我在任何方法中包含一个静态类文件 ( public static class Foo ),我都会收到此错误,无论该类是否被代码实际使用
- 产生错误时,不执行插件本身(异常发生在任何代码之前)

任何人以前见过这样的事情或对 System.TypeLoadException 有任何了解异常(exception)?

最佳答案

我刚刚使用 CRM Online 试用实例 (5.0.9690.3358) 尝试了这个插件并且正在工作。

插件在创建消息、任务实体、预操作、同步上注册。

using System;
using Microsoft.Xrm.Sdk;

namespace TestPlugin
{
public class MyPlugin : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName != "task")
return;

try
{
entity.AddOrUpdate("description", "updated by plugin");
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
}
}
}

public static class ExtensionMethods
{
public static void AddOrUpdate(this Entity e, string propertyName, object value)
{
if (e.Attributes.Contains(propertyName))
{
e.Attributes[propertyName] = value;
}
else
{
e.Attributes.Add(propertyName, value);
}
}

}
}

这可以确保问题不是扩展方法。

我最好的猜测(按顺序):
  • 您的解决方案中的一个项目是使用 .NET Framework 4.5 编译的
  • 您使用的是旧版 SDK
  • 您正在使用旧的插件注册工具
  • 关于dynamics-crm-2011 - 导致TypeLoad异常的CRM 2011在线实例的扩展方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16371389/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com