Question

Naseer83 on Wed, 16 Apr 2014 17:10:57


Hi

I have a desktop application , it was in framework 3.5, later i added unit test project in to it which has Framework 4.

it was working fine without any issue.

Now i have changed framework of my Project to 4.0 also but now unit test project no longer compiles and gives error:

Error 2 Could not load file or assembly 'MyApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

Is there any setting i need to chagne as well, both projetcs are in x86,

Any help here will be much appreciated.

Regards



Sponsored



Replies

CoolDadTx on Wed, 16 Apr 2014 18:59:57


When you created the unit test did you add it as a project reference?  If so then it should be fine and the problem lies in one of its dependencies. 

Michael Taylor
http://msmvps.com/blogs/p3net

PaulLinton on Thu, 17 Apr 2014 04:17:22


In the Unit Test project try removing the reference to the main application (MyApplication) and then add it in again.

Naseer83 on Thu, 17 Apr 2014 11:09:40


Hi,

i have tried removing and adding reference but still does not work.

When i added unit test project it was working fine, now when i changed the framework of main application then unit test project making problem and does not compile.

CoolDadTx on Thu, 17 Apr 2014 13:47:17


Hold up, you're getting a compilation error and not a runtime error? 

If you switch your main project back to v3.5 does it compile again?  All you're doing is going into the project's properties and changing the framework version to .NET v4?  Are you perhaps choosing .NET 4.5 or later instead?  What platform is the main project and unit test projects compiling against?  When you add a reference are you using the Solution tab to select the project and not using Browse to go find the binary?

Naseer83 on Thu, 17 Apr 2014 14:02:28


If I Switch main project back to 3.5 it wont compile now as i am using String.joins override with was not available in 3.5, but if i remove that call it will compile in 3.5 as well.

When i add reference of main project in unit test project i refer to Project not to dll in bin.

currently both main and unit test project are in 4.0.

CoolDadTx on Thu, 17 Apr 2014 14:26:55


Create a new unit test project targeting v4.  Add a reference to your main project along with a simple unit test.  Try to compile and see if it works.

Jack-Zhai on Fri, 18 Apr 2014 08:04:12


Thanks for CoolDadTx’s help.

Hi Naseer83,

My suggestion is that you could delete the bin/debug folder in your desktop app folder, and then clean and rebuild your desktop app, and then add the specific dll file as the references of your unit test project.

The real issue is that you need to check whether your desktop app get any error/warnings in your side, so we could make sure that whether it is your test project/ desktop app issue. Of course, if we make sure that it would be the test issue, as CoolDadTx's suggestion, create a new test project, test it again. Please also remove the dll file in your test project path, and then re-add it as the reference. 

Best Regard

Naseer83 on Fri, 18 Apr 2014 12:39:42


I tried all things but none work except creating new project.

But still there is a strange behavior with new project that when i try to create unit test for any method by just right clink n it and selecting create unit test  option after that new unit test project starts giving same error as old even after deleting newly created test class it still continues to give error, so for time being i have  created  a new project and adding all test classes manually in it and this way it is working,

Thanks for all your time and help.

Jack-Zhai on Mon, 21 Apr 2014 03:25:20


Hi Naseer83,

Glad to see that this issue has been resolve, maybe the previous project’s files are corrupted. Anyway, since it worked well now, I will mark and close this case. Thanks for supporting my work.

But still there is a strange behavior with new project that when i try to create unit test for any method by just right clink n it and selecting create unit test  option after that new unit test project starts giving same error as old even after deleting newly created test class it still continues to give error.

For this issue, you know that one thread for one issue, so it would be better if you open up a new thread for the new question. In this way, our discussion here will not deviate too much from the original issue.

Please also share us the detailed error message in your new thread you got when you create the test. Thanks for your understanding.

Best Regard,