4

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.

2
  • The reference assemblies for .NET 4.5 are in c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5, not v4.0. Does your program contain an explicit reference to the reference assembly path? (Actually, I'm not sure from your question whether you're attempting to build your project for .NET 4.0 or for 4.5. In the former case, the problem would be that you aren't using the reference assembly for System.dll, but rather the system assembly.)
    – user743382
    May 27, 2013 at 12:40
  • That's got it. Thanks very much. (I had the project set to target .net 4.0 but it should have been .net 4.5) May 27, 2013 at 12:49

4 Answers 4

8

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.

3
  • Thanks for the further information on this issue. I got the project working by switching the target to 4.5, I'm not too concerned about what framework it runs under but it's good to know I can still get it to target .NET 4.0 building on Windows 8. (I didn't fully understand the point of the Reference Assemblies, but your answer stackoverflow.com/questions/9701135/… was helpful) May 28, 2013 at 9:00
  • This answer is all correct. If we look at the documentation for this type, we can conform that in .NET 4.0 this type was in the assembly PresentationCore.dll, while in .NET 4.5 it had been moved to the assembly System.dll. Oct 19, 2013 at 9:43
  • I had the same error but the problem in my case was the location of PresentationCore.dll was .../v3.0 which had to be changed.Very good answer
    – YKa
    Apr 9, 2014 at 23:51
2

I had a similar problem with fxcopcmd V12. I was able to solve it by explicitly adding

/reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\WindowsBase.dll"

See: FxCop engine exception on WPF assembly

0

Take a look at this similar post, How can I resolve this? The unit type exists in two dll files, it suggests that you are referencing two assemblies with the same type, so you would need to give the type you want to use the fully quantified name.

1
  • That's a workaround, not a fix. In this case, the type shouldn't be defined in two different assemblies.
    – user743382
    May 27, 2013 at 12:39
0

We had the same problem with our libraries after moving to a new build server.

The solution was to specify the path of the .net framework to build against:

/p:FrameworkPathOverride="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"

If the .net 4.0 framework (Multi-Targeting Pack) is not installed on the build server (as it was with us), you can just copy the "v4.0" folder with all its assemblies to the build server ;)

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.