I have some NUnit tests on .net 4.5.1 class library against PCL and both use SQLite.Net PCL, the former uses its Win32 platform.
When running from a test runner (like CodeRush Unit Test Runner) it works just fine.
But NCrunch would throw an exception when trying to create a SQLiteConnection instance:
path = Path.GetTempFileName();
connection = new SQLiteConnection(new SQLitePlatformWin32(), path); // exception thrown here
SetUp : System.TypeInitializationException : The type initializer for ‘SQLite.Net.Platform.Win32.SQLiteApiWin32Internal’ threw an exception.
—-> System.Exception : Failed to load native sqlite library
I’ve found out that this behavior is due to the missing Interop assemblies that aren’t copied by NCrunch by default (x64 and x86 folder in bin\Debug folder) to optimize the unit testing process.
Hence adding these two folders to “Additional files to include” NCrunch project configuration property does the trick – that way NCrunch will include the missing assemblies.
Find more info about troubleshooting missing files when NCrunching here.