System.Security.Permissions.FileIOPermission when using MEF to load dll's

元气小坏坏 提交于 2020-01-04 18:56:49

问题


I am trying to load some dll's into a MEF DirectoryCatalog within an ASP.NET MVC application:

var catalog = new DirectoryCatalog(HttpRuntime.BinDirectory, "Toptable.Mobile.*.dll");

When I run the app through the Cassini web server (i.e. F5) everything runs fine however when hosted in IIS(7) I get the following exception:

[SecurityException: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.]
   System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
   System.Security.CodeAccessPermission.Demand() +54
   System.IO.Path.GetFullPath(String path) +193
   System.ComponentModel.Composition.Hosting.DirectoryCatalog.GetFullPath(String path) +267
   System.ComponentModel.Composition.Hosting.DirectoryCatalog.Initialize(String path, String searchPattern) +144
   System.ComponentModel.Composition.Hosting.DirectoryCatalog..ctor(String path, String searchPattern) +166
   Toptable.Mobile.MvcApplication.Application_Start() in C:\Dev\Toptable\Toptable.Mobile\Toptable.Mobile.Web\Global.asax.cs:74

The .NET trust levels for the application are set to "Full" both for the site and globally and I have set the trust level in web.config (system.web/trust) to Full. Running out of ideas about what could be causing it. Any suggestions?


回答1:


if youre sure youre in full trust is more likely a path/permissions error. are you sure the path youre after is accessible?




回答2:


The exception makes it look like you aren't actually running in full trust. Check the AppDomain.IsFullyTrusted property to verify that you are. If you are, then it may be the case that ASP.NET is running as an OS user with reduced privileges under IIS, and it doesn't have permission to call GetFullPath. As a workaround you could scan the directory yourself, create an AssemblyCatalog for each DLL, and add all of the AssemblyCatalogs into an AggregateCatalog.



来源:https://stackoverflow.com/questions/3264903/system-security-permissions-fileiopermission-when-using-mef-to-load-dlls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!