tags:

views:

31

answers:

2

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?

A: 

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

Andrew Bullock
Yes on both counts :(
James Hollingworth
A: 

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.

Daniel Plaisted