Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit testing 3.5 project in VS2010 yields CS1685 warnings

I have a project in development that targets .NET 3.5. I have no choice about this as the corporate big-wigs will not let us target 4.0. I've added a new Test Project to the solution in Visual Studio 2010. I see that I can only target the 4.0 Framework from the test project (which is okay because it's not deployed).

Everything is great except that I get compiler warnings from my test projects:

warning CS1685: The predefined type 'System.Action' is defined in multiple assemblies in the global alias; using definition from 'c:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Core.dll'

I removed the reference to System.Core from the test project and the warning is still occurring. I can only assume it is because the project I am testing is targeting 3.5 so something is getting crossed up. Is there a CLEAN way to eliminate this warning until we are given approval to target 4.0 in our apps?

like image 781
SonOfPirate Avatar asked Mar 03 '11 18:03

SonOfPirate


1 Answers

It sounds like you are using MSTest as your unit testing framework. If so the problem is that MSTest does not support down targeting in Visual Studio 2010. This means it will load the 4.0 version of the .Net assemblies even if the project your testing is targeting 3.5. This causes the conflicts you are seeing due to the multiple versions of System.Core which get loaded in this scenario.

Sadly there is no way to work around this problem other than to upgrade your project to 4.0.

like image 53
JaredPar Avatar answered Oct 25 '22 04:10

JaredPar