Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting a FileNotFound exception when referencing another project from the same solution?

Tags:

c#

.net

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.

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

like image 905
Alex Baranosky Avatar asked Feb 08 '09 02:02

Alex Baranosky


2 Answers

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.

like image 153
Marc Gravell Avatar answered Sep 21 '22 04:09

Marc Gravell


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?

like image 31
shahkalpesh Avatar answered Sep 20 '22 04:09

shahkalpesh