强文[注释实体中的插件错误] [1]
[1]: http://i.stack.imgur.com/hRIi9.png
嗨,任何人都解决了我的问题我收到了插件错误,我在更新“注意”实体工作。基本上我想要一个将预先退出的注释附件XML文件转换为新的插件 .MMP 具有相同名称的扩展文件。 我已经完成了以下程序,首先我创建了一个“ Converter_Code.cs ”dll,其中包含将 XML文件转换为.MMP文件的 Convert()方法这是该类的构造函数。
public Converter(string xml, string defaultMapFileName, bool isForWeb)
{
Xml = xml;
DefaultMapFileName = defaultMapFileName;
Result = Environment.NewLine;
IsForWeb = isForWeb;
IsMapConverted = false;
ResultFolder = CreateResultFolder(MmcGlobal.ResultFolder);
}
在ConvertPlugin.cs插件类中我首先使用以下方法在字符串中检索Note实体附件XML文件
IPluginExecutionContext context =(IPluginExecutionContext)serviceProvider.
GetService (typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory= (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService
(context.UserId);
if (context.InputParameters.Contains("Target")
&& context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
var annotationid = entity.GetAttributeValue<Guid>("annotationid");
if (entity.LogicalName != "annotation")
{
return;
}
else
{
try
{
//retrieve annotation file
QueryExpression Notes = new QueryExpression { EntityName ="annotation"
,ColumnSet = new ColumnSet("filename", "subject", "annotationid",
"documentbody") };
Notes.Criteria.AddCondition("annotationid", ConditionOperator.Equal,
annotationid);
EntityCollection NotesRetrieve = service.RetrieveMultiple(Notes);
if (NotesRetrieve != null && NotesRetrieve.Entities.Count > 0)
{
{
//converting document body content to bytes
byte[] fill = Convert.FromBase64String(NotesRetrieve.Entities[0]
.Attributes["documentbody"].ToString());
//Converting to String
string content = System.Text.Encoding.UTF8.GetString(fill);
Converter objConverter = new Converter(content, "TestMap", true);
objConverter.Convert();
}
}
}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("something is going wrong");
}
}
}
}
和一个字符串作为参数传递给“ Converter ”构造函数。
最后我使用ILMerge以下方法合并了所有dll:
的 ilmerge /out:NewConvertPlugin.dll ConvertPlugin.dll Converter_Code.dll
并且 NewConvertPlugin 已成功注册,但在其工作时会生成以下错误:
插件的意外异常(执行):ConverterPlugin.Class1:System.Security.SecurityException:该程序集不允许部分信任的调用者。 我也使用错误日志调试插件,但它没有工作,所以我无法得到一个错误的原因。
答案 0 :(得分:1)
错误是由您在插件中合并的库引起的。
首先,您使用的是CRM Online(来自您的屏幕截图),而使用CRM Online,您只能在沙盒中使用注册插件。
Sandbox意味着您的插件有限,并且它们在部分信任环境中运行。
您合并了一个需要完全信任权限的外部库,因此您的插件无法正常工作,这就是您出错的原因。
因为您在CRM Online中,或者您找到了另一个只需要部分信任的库(转换器),希望合并过程能够正常工作,或者您包含(如果有的话)转换库的源代码直接进入你的插件。