38998

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

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?

Answer1:

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

Answer2:

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.

Recommend

  • Why does this LinQ query not like chars?
  • Reading old clipboard data in new program version in C#
  • Localization using resources file not working
  • Azure Bot Framework Emulator Error - System.ArgumentNullException: Value cannot be null
  • Target the XNA framework in ordinary Visual Studio 2012 project
  • Nuget Assembly reference Microsoft Owin after upgrade to 3.0.1
  • Using curl with Phalanger
  • VS2013 Build Definition 'Microsoft.TeamFoundation.Client.BasicAuthCredential' is not marke
  • Robotium & system dialogs
  • TryParse double values
  • Entity Framework on SQL Server CE without driver install
  • Gephi's java default method not implemented in C# with an ikvm-from dll library
  • Windows 10 Bluetooth Gatt Client ValueChanged issue
  • How does the scala compiler locate the positions for variance annotation
  • Activation error occured while trying to get instance of type LogWriter, key “”
  • How to resolve this packager error on react native Android
  • Authentication failed with Azure Active Directory in Windows Phone
  • Retrieve IP address of device
  • Installing PHP 7 on digitalocean
  • C# fibonacci function returning errors
  • How to get current document uri in XSLT?
  • cygwin cannot exec 'git-add--interactive' permission denied
  • Convert Type Decimal to Hex (string) in .NET 3.5
  • What is the purpose of TaskExecutor in spring?
  • Problems installing Yesod for Haskell
  • Mysterious problem with floating point in LISP - time axis generation
  • How to set ini file attributes during an Inno install
  • Deserializing XML into class C#
  • Timeout for blocking function call, i.e., how to stop waiting for user input after X seconds?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • How to include full .NET prerequisite for Wix Burn installer
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • Proper folder structure for lots of source files
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • How do I configure my settings file to work with unit tests?
  • How does Linux kernel interrupt the application?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize