2015-11-20 52 views
0

我有一個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"); 
        } 
       } 
      } 

回答

0

我的插件代碼,你在網上組織中運行的插件?在這種情況下,您不能在註冊組件時將組織設置爲模式。

+0

嗨馬可,這是一個本地版本的CRM實際上,我將模式設置爲無,但仍然沒有運氣,因爲沙盒模式無法訪問文件系統,我得到同樣的錯誤,任何想法? – Papi

+0

我看到您在插件上使用Console.WriteLine,它不會對任何效果進行排序,並且您嘗試訪問C:\ Team CRM \ Warp.csv。這是你的本地驅動器還是服務器?我懷疑CRM有權訪問沙盒外的那個位置 – MaPi

+0

它位於我的本地機器上,是的,我也將它添加到服務器,所以你有什麼建議,我還能如何得到這個工作? – Papi

1

假設這是一個同步(異步可能會在不同的服務器上運行,具體取決於您的部署)插件,請檢查用戶運行的IIS帳戶是否具有該文件夾的權限。如果沒有,那麼你會得到你所看到的文件權限錯誤。

相關問題