The key 'Moles' cannot be found

474 views Asked by At

I create a unit-test project for my solution and I'm using Moles to detour all data reading. When today I launch all tests, at end the result was an error like this "the hosttype "Moles" cannot be loaded: The key 'Moles' cannot be found." for every test that contains the attribute HostType("Moles").

I don't understand the reason of problem because I'm using Moles from three months ago and I never have had this kind of problem.

Thanks!!!

1

There are 1 answers

0
SouthShoreAK On

This is a very old question, and the asker has likely found a solution by now, but as this is one of the first results for this error in Google, here is what I have found:

I (and many others, seemingly) encountered this issue when running 64-bit tests that depend on Moles.

First, make sure you have the correct "bitness" of moles installed. There are x86 and x64 versions of the moles framework. It was my experience that the 32-bit framework installed on a 64-bit machine will actually look like everything is working properly, but your tests will not run. You can install the 64-bit framework here:

Moles 64 bit Framework

I recommend closing VS 2010 before you install, but I don't know if it makes any difference.

Next, make sure, one way or another, that your Moles-hosted tests are using 64 bit if they need to. To achieve this, I left my testing host as "Default", but set the following in my test project's AssemblyInfo.cs file:

[assembly: MolesAssemblySettings(Bitness = MolesBitness.x64)]

Then, only for the tests I wanted to run in Moles, I added this attribute to the test method:

[HostType("Moles")]  

After this, everything worked for me.