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:
- Check the folder permissions on the
packages
directory, where the DLL lives - Ensure that the Iesi.Collections DLL is being copied to bin\Debug on build
- Check that the NHibernate settings are sane (they match those of a project that works for me)
- 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.)
- Manually re-associating the DLL from the
packages
directory to the C# project. No effect. - Because the DLL has a public key token, I know the DLL is signed - so that's not it, either.
- 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.
- Checked that the DLL is not blocked by Windows by viewing the Properties; it's not blocked.
- 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.
- Despite my SpecFlow version being 1.9.2, I noticed that
Castle.Core
,NHibernate.ByteCode.Castle
, andlog4net
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.) - 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.
- 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.
- 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?
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!