我有一個CRM插件觸發表單上一個字段的更新,然後插件應該利用SDK的導入功能將CSV記錄導入到動力,我得到的foloowing錯誤CRm Dynamics 2013插件錯誤,請求獲得類型爲xxx的許可失敗
請求類型的許可 'System.Security.Permissions.FileIOPermission,mscorlib程序, 版本= 4.0.0.0,文化=中性公鑰= b77a5c561934e089' 失敗。
我已經將隔離模式下的插件註冊設置爲NONE而不是Sandbox,但我仍然收到錯誤,以及爲什麼會發生這種情況以及我如何解決它。它在ImportData函數中封裝的ImportFile部分失敗。
請參考下面
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");
}
}
}
嗨馬可,這是一個本地版本的CRM實際上,我將模式設置爲無,但仍然沒有運氣,因爲沙盒模式無法訪問文件系統,我得到同樣的錯誤,任何想法? – Papi
我看到您在插件上使用Console.WriteLine,它不會對任何效果進行排序,並且您嘗試訪問C:\ Team CRM \ Warp.csv。這是你的本地驅動器還是服務器?我懷疑CRM有權訪問沙盒外的那個位置 – MaPi
它位於我的本地機器上,是的,我也將它添加到服務器,所以你有什麼建議,我還能如何得到這個工作? – Papi