Wednesday, June 8, 2011

Running Machine.Specifications console runner in mixed mode

Our test project has just been upgraded to .NET 4.0. That caused some problems with the .NET 2.0 references, particularly SQLite. Here's the error you get right after a Nuget install:


NHibernate.HibernateException: Could not create the driver from NHibernate.Driver.SQLite20Driver, NHibernate, Version=3.1.0.4000, Culture=neutral, PublicKeyToken=aa95f207798dfdb4. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Unable to find the requested .Net Framework Data Provider.  It may not be installed.

This is a well-known issue. Basically, SQLite is a .NET 2.0 targeted app. I am working in .NET 4.0. I followed Mohamed Meligy's instructions and added some edits to my test assembly's configuration file (app.config).


ReSharper and MSPEC ran my specs just fine. So, I then ran my MSBUILD project. I have a target that runs the mspec.exe console runner. I get the HibernateException again.


What gives?


Well, it turns out that the executables that you "nuget" from the package don't include configuration files. Sure, I had the edits for running mpsec from within Visual Studio's IDE using ReSharper's TestRunner. But mspec.exe is its own AppDomain -- you still need those configuration edits there.


To apply the configuration edits, you need a file. The nuget package didn't create them, so I did it manually.


In my packages/Machine.Specifications.0.4.12/tools folder, I created an mspec.exe.config file, and one for each of the other exe's. Inside, I placed the startup node with the legacy redirect. Additionally, I added the system.data node. Now, each mspec executable will leverage the mixed-mode framework setup to make SQLite happy.


Now, all tests pass just as they do in my test runner within my IDE.