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

I am trying to load some dll into the MEF DirectoryCatalog directory in an ASP.NET MVC application:

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

When I run the application through the Cassini web server (i.e. F5), everything works fine, but when placed 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 around the world, and I set the trust level in web.config (system.web / trust) to Full. Launching ideas on what might be causing this. Any suggestions?

+2
source share
2 answers

If you are sure that you are in complete trust, this is most likely a path / permission error. Are you sure that the path after you is accessible?

0
source

An exception makes it look like you really don't fully trust. Check the AppDomain.IsFullyTrusted property to make sure you are. If so, then it may happen that ASP.NET is running as a user with limited rights in IIS and does not have permission to call GetFullPath. As a workaround, you can scan the directory yourself, create an AssemblyCatalog for each DLL, and add all AssemblyCatalogs to the AggregateCatalog.

0
source

All Articles