NUnit \"could not load file or assemby 'MyTest

2019-02-11 10:37发布

问题:

I'm setting up a new 64 bit machine to run as a build server. When I try to load my NUnit test assembly into NUnit GUI I get the following error.

There is nothing obvious missing, all the dependencies seem to be present. All the DLLs are compiled for the x86 platform.

Using NUnit 2.4.7. I have tried upgrading to 2.4.8 but the same error occurs.

System.IO.FileNotFoundException: Could not load file or assembly 'MyTestProject' or one of it's dependencies. The system cannot find the file specified.

System.IO.FileNotFoundException...

Server stack trace: 
   at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
   at System.Reflection.Assembly.Load(String assemblyString)
   at NUnit.Core.Builders.TestAssemblyBuilder.Load(String path)
   at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, Boolean autoSuites)
   at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, String testName, Boolean autoSuites)
   at NUnit.Core.TestSuiteBuilder.BuildSingleAssembly(TestPackage package)
   at NUnit.Core.TestSuiteBuilder.Build(TestPackage package)
   at NUnit.Core.SimpleTestRunner.Load(TestPackage package)
   at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
   at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
   at NUnit.Core.RemoteTestRunner.Load(TestPackage package)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at NUnit.Core.TestRunner.Load(TestPackage package)
   at NUnit.Util.TestDomain.Load(TestPackage package)
   at NUnit.Util.TestLoader.LoadTest(String testName)

回答1:

The solution was to build the test project for "AnyCPU" instead of 32-bit. I can work around the restriction that made us use 32 bit.

Thank you David and Joe90 for the suggestions. I've certainly learned a couple of new things. fuslogvw.exe is awesome, I didn't previously know it existed.



回答2:

If you do need to build the test project for x86, you can use nunit-x86.

See "NUnit on 64-Bit Platforms" at http://www.nunit.org/index.php?p=nunit-gui&r=2.4.2.



回答3:

Activate the Fusion log with fuslogvw.exe (Run as Administrator from the Visual Studio Command Prompt) to see what the assembly loader tries to load and all occurring errors.



回答4:

The solution was found following this post: "Could not load file or assembly 'X.dll' or one of its dependencies. The specified module could not be found." - on host server and more specifically by using http://dependencywalker.com/