在执行System.Management.Automation.Runspaces.Runspace.Open方法时,可能 会报需要加载的模块‘DistributedCacheAdministration’不能被加载,这个问题困扰我快两天了,今天终于在MSDN的blog上看到一个解决办法。灰常感谢呀。解决办法如下:
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.
Source=System.Management.Automation
WasThrownFromThrowStatement=false
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.我的默认是32位,但机器是64位的,所以……
原文链接:http://blogs.msdn.com/b/rjacobs/archive/2010/05/04/the-specified-module-distributedcacheadministration-was-not-loaded-because-no-valid-module-file-was-found-in-any-module-directory.aspx