1

I am upgrading a solution to Visual Studio 2012 (and 2013, but that's a side issue)

I am encountering the following error (many times) when compiling the test projects:

Error 345 The type 'System.Action' exists in both 'c:\Users\neil\Documents\Visual Studio 2013\Referenced Assemblies\Third Party Dlls\Moq\Moq.dll' and 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Core.dll' .....

We are using Moq 4.0000, and the solution is using .Net 3.5 in all projects. It looks like the .Net framework now has a System.Func<....> implementation (previously only defined in Moq?) Oddly we haven't had this problem with VS2008, also using .Net 3.5.

Does anyone know how to resolve this?

haughtonomous
  • 4,602
  • 11
  • 34
  • 52
  • Are sure you are referencing the Moq assembly built for .NET 3.5? – Patrick Quirk Jul 03 '14 at 14:08
  • 1
    See [this question](http://stackoverflow.com/questions/7331432/existing-same-reference-on-different-dlls-in-net4-0), possible duplicate. Just not sure why a new Visual Studio version would throw this error and the older one wouldn't. – Patrick Quirk Jul 03 '14 at 14:13
  • Probably, but the latest one available is dated 2011, which precedes VS2012 anyway. – haughtonomous Jul 03 '14 at 15:12
  • An extra puzzle is that in VS2008 and VS2012 all projects are set to use .Net 3.5. So why the clash in VS2012 when VS2008 happily compiles? – haughtonomous Jul 03 '14 at 15:17

1 Answers1

0

Action and Func with many parameters were added only with .NET 4.0. Was it initially a .NET 2.0 project? In that case, you can try to remove the System.Core.dll from the references and try to see if the project compiles. Despite the name, it is unessential and was added only with .NET 3.5. The cleanest solution would be to upadate your library, Moq, with an updated one that fixes the clash in .NET 4.0. If that is not an option, follow Pratick advice to use assembly extern aliases.

ceztko
  • 14,736
  • 5
  • 58
  • 73
  • Not sure how extern aliases will help me. The problem is that both System.Core and Moq seem to define these delegates in the System namespace. – haughtonomous Jul 03 '14 at 15:15
  • 1
    Ignore that. I see now that the alias would enable me to qualify the class, eg MyAlias.Func<...> – haughtonomous Jul 03 '14 at 15:19