Error loading .NET 4.0 assembly in TeamCity using MSpec

When we migrated our tests from NUnit to MSpec (Machine.Specifications), we encountered the following error:

Could not load file or assembly 'file:///C:\BuildAgent\work\c7e220bd4bfc29dc\bin\dependencies\SomeProject.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

After some Googling, I realized that the default MSpec runner (MSpec.exe) was not built using .NET 4.0. Because our assembly (SomeProject.dll in the error above) was a .NET 4.0 assembly, we were getting this error.

The fix was to use the mspec-clr4.exe executable as the test runner instead. This exe is shipped with newer versions of MSpec (we're on Machine.Specifications version 0.5). The clr4 version of the runner is built on .NET 4.0 and works perfectly.

To do this in TeamCity, simply add the full path to the exe in the "Path to MSpec.exe" field in TeamCity's MSpec build step. Even though the field label says it is expecting MSpec.exe, if you give it a path to mspec-clr4.exe, it will use it.

This entry was posted in .NET, Continuous Integration, MSpec, TeamCity and tagged , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*
*