Search code examples
wpfvisual-studio-2012.net-4.5

The type 'System.Windows.Input.ICommand' exists in both 'PresentationCore.dll' and 'System.dll'


I've got this error that I just can't figure out.

I'm using VS 2012 (VS11) on Windows 8 with .net4.5 and I get this error when compiling a project that worked with VS 2010 and .net4.0.

This is the full error:

The type System.Windows.Input.ICommand exists in both 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\PresentationCore.dll' and 'c:\Windows\Microsoft.NET\Framework\v4.0.30319\System.dll'

If anybody could provide some insight on what is causing it and/or how to fix it I'd be grateful.

Thanks.


Solution

  • c:\Windows\Microsoft.NET\Framework\v4.0.30319\System.dll

    The message is accurate, ICommand indeed exists in both assemblies for .NET 4.5. The problem is your reference to System.dll, your project is using the wrong one. The assemblies in the Microsoft.NET directory are no longer suitable to act as reference assemblies, like they were in versions of .NET prior to .NET 4.0. They should no longer be there but unfortunately are required to support System.CodeDom and get C++/CLI projects built.

    Your reference to PresentationCore.dll is correct, it uses the c:\program files\reference assembly subdirectory. The proper home for reference assemblies in .NET 4.0 and up. These assemblies are special, they contain only metadata and are not a copy of the runtime assemblies.

    You'll need to fix your project. System.dll is probably not the only assembly that has this problem. Open the References node of your project and verify them one by one. Remove bad ones that point to Microsoft.NET and replace them with good ones by using Project + Add Reference. Best to just replace them all to be sure.