如何解决Dynamics CRM插件System.Security.Permissions.FileIOPermission错误 [英] How to resolve Dynamics CRM Plugin System.Security.Permissions.FileIOPermission error

查看:401
本文介绍了如何解决Dynamics CRM插件System.Security.Permissions.FileIOPermission错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

业务流程错误 System.Security.SecurityException::请求类型为" System.Security.Permissions.FileIOPermission "的权限,mscorlib,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089 ' 失败的. 在System.Security.CodeAccessSecurityEngine.Check处(对象需求,StackCrawlMark& stackMark,布尔值isPermSet) 在System.Security.CodeAccessPermission.Demand() 在System.IO.FileStream.Init(字符串路径,FileMode模式,FileAccess访问,Int32权限,布尔useRights,FileShare共享,Int32 bufferSize,FileOptions选项,SECURITY_ATTRIBUTES secAttrs,字符串msgPath,布尔bFromProxy,布尔useLongPath,布尔checkHost) 在System.IO.FileStream..ctor处(字符串路径,FileMode模式,FileAccess访问,FileShare共享,Int32 bufferSize,FileOptions选项,String msgPath,布尔bFromProxy,布尔useLongPath,布尔checkHost) 在System.IO.File.InternalWriteAllBytes(字符串路径,Byte []字节,布尔值checkHost) 在RetrieveAttachments.RetrieveClass.Execute(IServiceProvider serviceProvider) 失败的动作是: 要求 失败的第一个权限的类型为: System.Security.Permissions.FileIOPermission 失败的装配体区域是: 我的电脑

Business Process Error System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) at System.Security.CodeAccessPermission.Demand() at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.File.InternalWriteAllBytes(String path, Byte[] bytes, Boolean checkHost) at RetrieveAttachments.RetrieveClass.Execute(IServiceProvider serviceProvider) The action that failed was: Demand The type of the first permission that failed was: System.Security.Permissions.FileIOPermission The Zone of the assembly that failed was: MyComputer

我还在插件AssemblyInfo.cs文件中添加了以下方法 [程序集:System.Security.AllowPartiallyTrustedCallers] 但它会引发相同的错误.

I also added following method in plugin AssemblyInfo.cs file [assembly: System.Security.AllowPartiallyTrustedCallers] but its raise same error.

QueryExpression notes = new QueryExpression { EntityName = "annotation", ColumnSet = new ColumnSet("filename", "subject", "annotationid", "documentbody","mimetype") };
notes.Criteria.AddCondition("annotationid", ConditionOperator.Equal, annotationid);
     EntityCollection NotesRetrieve = service.RetrieveMultiple(notes);
     if (NotesRetrieve != null && NotesRetrieve.Entities.Count > 0)
     {
      foreach (var note in NotesRetrieve.Entities)
      {
       string fileName = note.GetAttributeValue<string>("filename");
       string cleanFileName = string.Empty;
       foreach (var chr in fileName.ToCharArray().ToList())
       {
        if(!Path.GetInvalidFileNameChars().Contains(chr)) cleanFileName = cleanFileName + chr; 
       }
     FileIOPermission f = new FileIOPermission(FileIOPermissionAccess.Write, @"D:\note");
     string fileLocation = Path.Combine(@"D:\note", cleanFileName);
     byte[] fileContent = Convert.FromBase64String(NotesRetrieve.Entities[0].Attributes["documentbody"].ToString());
     System.IO.File.WriteAllBytes(fileLocation, fileContent);
    }
   }

推荐答案

禁止从沙盒插件读取文件.尝试将隔离模式更改为无.

Reading file from a sandbox plugin is prohibited. Try to change isolation mode to none.

这篇关于如何解决Dynamics CRM插件System.Security.Permissions.FileIOPermission错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆