为什么我来自同一个解决方案引用另一个项目时,我得到一个FileNotFound例外? [英] Why am I getting a FileNotFound exception when referencing another project from the same solution?

查看:213
本文介绍了为什么我来自同一个解决方案引用另一个项目时,我得到一个FileNotFound例外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习如何使用NUnit的。我有我在它的解决方案主要项目,并创造了一种将举行我的单元测试,用它自己的命名空间中相同的解决方案一个独立的项目。从这个项目中,我添加到主项目的引用,并添加

I am learning how to use NUnit. I have my main project in it's solution, and created a separate project in that same solution which will hold my unit tests, with it's own namespace. From that project I add a reference to the main project and add a

using MainProjectNamespace;



到它的顶部。

to the top of it.

当我去NUnit的,任何测试我有没有参考的主要项目工作。这些测试中,我只是设置习惯NUnit的,而且几乎无用。当NUnit的运行真实测试的测试抛出此异常:

When I go to NUnit, any tests I have that don't reference the main project work. These are tests I setup just to get used to NUnit, and are pretty much useless. When NUnit runs the real tests the test throws this exception:

TestLibrary.Test.TestMainProject:
System.IO.FileNotFoundException:找不到
无法加载文件或程序
'WpfApplication2,版本= 1.0.0.0,
区域性=中性公钥=空'
或它的一个依赖。在
系统找不到指定的文件。

TestLibrary.Test.TestMainProject: System.IO.FileNotFoundException : Could not load file or assembly 'WpfApplication2, Version = 1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the specified file.

为什么会出现此异常?

编辑:

现在,当我尝试加载组装成NUnit的,它甚至不会加载(所以我不能连得机会来运行测试)

Now when I try to load the assembly into NUnit, it won't even load (so I can't even get a chance to run the tests)

这是前来异常SUP,堆栈跟踪:

This is the Exception that come sup, and the stack trace:

系统.IO.DirectoryNotFoundException:找不到路径的一部分长路径这里,我并不想输入

System.IO.DirectoryNotFoundException: Could not find a part of the path 'LONG PATH HERE I DON'T WANT TO TYPE'

System.IO.DirectoryNotFoundException...

Server stack trace: 
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
    at System.IO.Directory.SetCurrentDirectory(String path)
    at NUnit.Core.DirectorySwapper..ctor(String directoryName)
    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.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.PrivateProcessMessage(RuntimeMethodHandle 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)

EDIT2:
上面的路径显然是在我的硬盘驱动器。

The above path clearly IS in my hard drive

EDIT3:
我刚从调试切换到释放,对NUnit的,并从TestingLibrary释放文件夹加载该dll ......它装! 3特定的命名空间的测试1的工作。 。取得了一些进展,我

I just switched from Debug to Release, on NUnit, and loaded the dll from the release folder of TestingLibrary... And it loaded! 1 of the 3 namespace-specific tests worked. Getting somewhere, I am.

EDIT4:
Welllllllll ......其实我可以运行测试了,但我回到原来的错误。它没有找到组装为主营项目

Welllllllll... I can actually run the tests now, but I am back to the original error. IT is not finding the assembly for the main project

推荐答案

编译器中删除所有未使用的引用,并没有不必要的部署DLL 。 A 使用(本身)不能算作一用。无论是通过复制到输出目录设置标记为部署DLL,或者添加一些代码的真正的使用在DLL中声明的类型。

The compiler removes all unused references, and doesn't deploy the dll unnecessarily. A using (by itself) does not count as a use. Either mark the dll for deployment via the "Copy to output directory" setting, or add some code that really uses types declared in the dll.

这篇关于为什么我来自同一个解决方案引用另一个项目时,我得到一个FileNotFound例外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆