我有一个CRM插件,可以触发表单上某个字段的更新,然后该插件应该利用SDK的导入功能将CSV记录导入Dynamics,我收到了以下错误
请求类型的许可 'System.Security.Permissions.FileIOPermission,mscorlib, Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089' 失败。
我已将插入隔离模式的插件设置为NONE,而不是Sandbox,但我仍然收到错误,任何想法为什么会发生这种情况以及我如何解决它。它在ImportFile部分失败,该部分封装在ImportData函数中。
请参阅下面的插件代码
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
if (context == null)
{
throw new ArgumentNullException("loaclContext");
}
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity supplyClaimsEntity = (Entity)context.InputParameters["Target"];
if (supplyClaimsEntity.LogicalName != "new_supplierclaimsupdate")
{
return;
}
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.InitiatingUserId);
string entityBeginUpload = "Start Upload";
try
{
string filePath = (@"C:\Team CRM\Warp.csv");
ImportData(service, new_topproducts.EntityLogicalName, filePath);
}
catch (FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> ex)
{
Console.WriteLine("The application terminated with an error.");
Console.WriteLine("Timestamp: {0}", ex.Detail.Timestamp);
Console.WriteLine("Code: {0}", ex.Detail.ErrorCode);
Console.WriteLine("Message: {0}", ex.Detail.Message);
Console.WriteLine("Inner Fault: {0}",
null == ex.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
}
catch (System.TimeoutException ex)
{
Console.WriteLine("The application terminated with an error.");
Console.WriteLine("Message: {0}", ex.Message);
Console.WriteLine("Stack Trace: {0}", ex.StackTrace);
Console.WriteLine("Inner Fault: {0}",
null == ex.InnerException.Message ? "No Inner Fault" : ex.InnerException.Message);
}
catch (System.Exception ex)
{
Console.WriteLine("The application terminated with an error.");
Console.WriteLine(ex.Message);
// Display the details of the inner exception.
if (ex.InnerException != null)
{
Console.WriteLine(ex.InnerException.Message);
FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault> fe = ex.InnerException
as FaultException<Microsoft.Xrm.Sdk.OrganizationServiceFault>;
if (fe != null)
{
Console.WriteLine("Timestamp: {0}", fe.Detail.Timestamp);
Console.WriteLine("Code: {0}", fe.Detail.ErrorCode);
Console.WriteLine("Message: {0}", fe.Detail.Message);
Console.WriteLine("Trace: {0}", fe.Detail.TraceText);
Console.WriteLine("Inner Fault: {0}",
null == fe.Detail.InnerFault ? "No Inner Fault" : "Has Inner Fault");
}
}
}
答案 0 :(得分:1)
假设这是同步(异步可能在不同的服务器上运行,具体取决于您的部署)插件,请检查用户正在运行的IIS帐户是否具有该文件夹的权限。如果没有,那么您将收到您所看到的文件权限错误。
答案 1 :(得分:0)
您是否在在线组织上运行该插件?在这种情况下,您无法在注册程序集时将组织设置为模式。