为什么在从同一解决方案引用另一个项目时会出现 FileNotFound 异常?
我正在学习如何使用 NUnit。 我的解决方案中有我的主项目,并在同一解决方案中创建了一个单独的项目,该项目将保存我的单元测试,并具有自己的命名空间。 从该项目中,我添加了对主项目的引用,并
using MainProjectNamespace;
在其顶部添加了 。
当我使用 NUnit 时,我所做的任何测试都不会引用主项目工作。 我设置这些测试只是为了习惯 NUnit,而且几乎没有什么用处。 当 NUnit 运行实际测试时,测试会抛出此异常:
TestLibrary.Test.TestMainProject: System.IO.FileNotFoundException: 无法加载文件或程序集 'WpfApplication2,版本 = 1.0.0.0, 文化=中立,PublicKeyToken=null' 或其依赖项之一。 这 系统找不到指定的文件。
为什么我会收到此异常?
编辑:
现在,当我尝试将程序集加载到 NUnit 中时,它甚至不会加载(所以我什至没有机会运行测试)
这是出现的异常,以及堆栈跟踪:
System.IO .DirectoryNotFoundException:找不到路径“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)
编辑2: 上面的路径显然在我的硬盘中
EDIT3: 我刚刚在 NUnit 上从“调试”切换到“发布”,并从 TestLibrary 的发布文件夹中加载了 dll...然后它就加载了! 3 个特定于命名空间的测试中有 1 个有效。 要去某个地方,我是。
编辑4: 好吧...我现在实际上可以运行测试,但我又回到了原来的错误。 IT 部门未找到主项目的组件
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.
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 :
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.
Why am I getting this exception?
EDIT:
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)
This is the Exception that come sup, and the stack trace:
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:
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... 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
编译器会删除所有未使用的引用,并且不会部署不必要的 dll。
using
(单独)不算是使用。 通过“复制到输出目录”设置将 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.您是否重命名了源项目中输出程序集或命名空间的名称?
看起来您的源文件是“WPFApplication1”& 我推测您可能已将输出类型从 dll 更改为 exe?
Did you rename the name of the output assembly OR namespace in the source project?
Looks like your source file is "WPFApplication1" & I am speculating that you might have changed the output type from dll to exe?
我遇到了同样的问题,RKitsons 的回答帮助了我。
基本上,我将项目依赖的所有 dll 以及 nunit.framework.dll 复制到同一目录中...obj/debug/ 这是实现此目的的一种方法。
优雅的方法是在 Visual Studio 中的“生成”选项卡下将项目配置更改为发布模式,如果项目设置正确,则应将所有依赖的 dll 复制到适当的“out”或“release”目录中。
I had the same problem and RKitsons answer helped me.
Basically I copied all the dll's that my project depends on as well as the nunit.framework.dll into the same directory...obj/debug/ THis is one way of doing it.
The elegant method is to change the project configuration , in Visual Studio, under the Build tab to release mode and if the project is setup correctly should copy all the dependent dll's into an appropriate "out" or "release" directory.
您在应用程序中引用的程序集之一似乎依赖于不在 bin 文件夹中的另一个程序集。
It looks like one of the assemblies you are referencing in your app has dependencies on another assembly which is not in your bin folder.