Access Denied on Iesi.Collections.dll

1.1k views Asked by At

For a project my team has recently started, I've been getting the following exception when I try to run my newly-created SpecFlow unit tests:

Could not load file or assembly 'Iesi.Collections, Version=1.0.1.0, Culture=neutral,
PublicKeyToken=aa95f207798dfdb4' or one of its dependencies. Access is denied.

Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4

...and the C# fragment that it is failing from looks like this:

private static ISessionFactory _sessionFactory;

// ... Further down in the class ...
public static void GenerateSchema()
{
    _sessionFactory = Fluently.Configure(new Configuration().Configure())
                      .Mappings(m => m.FluentMappings.AddFromAssembly(typeof(DataContext).Assembly))
                      .ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true))
                      .BuildConfiguration()
                      .BuildSessionFactory();
}

...and the fusion log looks like this:

=== Pre-bind state information ===
LOG: User = Unknown
LOG: DisplayName = Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
(Fully-specified)
LOG: Appbase = file:///C:/Projects/SomeProject/SomeProject.FeatureTest/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : NHibernate, Version=3.3.1.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Projects\SomeProject\FeatureTest\bin\Debug\SomeProject.FeatureTest.dll.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Iesi.Collections, Version=1.0.1.0, Culture=neutral, PublicKeyToken=aa95f207798dfdb4
LOG: Attempting download of new URL file:///C:/Projects/SomeProject/SomeProject.Web/bin/Debug/Iesi.Collections.DLL.
ERR: Failed to complete setup of assembly (hr = 0x80070005). Probing terminated.

I (and my team) are stumped on this one, because we've tried the following things:

  1. Check the folder permissions on the packages directory, where the DLL lives
  2. Ensure that the Iesi.Collections DLL is being copied to bin\Debug on build
  3. Check that the NHibernate settings are sane (they match those of a project that works for me)
  4. Re-acquired the project from TFS; since I'm the only person this is happening to, I figured it could just be a case of a corrupted Get. This had no effect. (Be re-acquire, I mean I closed VS2012, deleted the existing folder, opened a fresh VS2012 instance, Get > Advanced > Get Specific Version, with both checkmarks checked.)
  5. Manually re-associating the DLL from the packages directory to the C# project. No effect.
  6. Because the DLL has a public key token, I know the DLL is signed - so that's not it, either.
  7. The code above can be ruled out, because this exact line has been used in two other projects to set up local DB schemas for unit testing purposes.
  8. Checked that the DLL is not blocked by Windows by viewing the Properties; it's not blocked.
  9. In the fusion log, I noticed that it's trying to download the DLL from the Web project, so I added Iesi.Collections.dll to the web project as well; no effect.
  10. Despite my SpecFlow version being 1.9.2, I noticed that Castle.Core, NHibernate.ByteCode.Castle, and log4net were missing, so I added those to the project that's doing the data access (C:\Projects\SomeProject\SomeProject.Core); no effect. (Added because those are in another project that I can run feature tests on, which means it's just this particular solution.)
  11. Due to some other conditions on other projects, I've been running VS2012 by default as Administrator; now that I'm desperate, I tried disabling that and running as myself, to no effect.
  12. Some additional StackOverflow research showed that another user conquered a similar problem by clearing their Temporary Internet Files, so I booted up CCleaner - no effect.
  13. More StackOverflow research revealed the tale of a guy who could solve his problems with a humble iisreset from the command line; I tried this, to no effect.

Question: What causes Iesi.Collections.dll to throw an Access Denied FileLoadException on NHibernate initialization?

2

There are 2 answers

1
Andrew Gray On BEST ANSWER

In ReSharper, there is a setting that is on by default to Shadow-copy assemblies being tested. It is found by going to Resharper | Options..., Tools | Unit Testing.

Disabling this option prevents the assemblies from being shadow-copied to a location that the DLL apparently lacks permissions to run from, thus resolving the problem.

tl;dr - Check your ReSharper settings!

1
Luty On

Did you get this DLL file from Internet? If yes, you must ensure that the DLL is not blocked by Windows. In order to check this, go to the file properties in Windows Explorer and verify that there is a button labeled "Unblock". If yes, your file is blocked, you must click on this button in order to unblock the binary file.