What to do if you get this error when unit testing Windows Server AppFabric Caching
Being new to unit testing code that invokes PowerShell I ran into this problem when trying to test code that was using the Windows Server AppFabric Caching cmdlets.
System.Management.Automation.Runspaces.RunspaceOpenModuleLoadException was unhandled by user code
Message=One or more errors occurred processing the module 'DistributedCacheAdministration' specified in the InitialSessionState object used to create this runspace. See the ErrorRecords property for a complete list of errors. The first error was: The specified module 'DistributedCacheAdministration' was not loaded because no valid module file was found in any module directory.
I borrowed some code from Stephen Kaufman’s blog to create a cache in my unit test. But when I ran it I got the exception above. This is happening because the Visual Studio Unit Test tool by default runs tests in a 32 bit process on my x64 machine.
What I need to do is to force Visual Studio to run the tests in an x64 process. You can do this by altering the local.testsettings file in your solution items.
Step 1 – Open the local.testsettings file
Step 2 – Set the Hosts to run in 64 bit
Note: The default is to force the tests to run in 32 bit processes.