I have an error, when I try to build my .net 4, c# project. Everything works great, but when I add an external reference to a given DLL, it stops working, it can't build, throws this type of some errors:
Error 36 The type 'System.Tuple' exists in both 'C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\mscorlib.dll' and 'C:\Projects\Project1\ExternalRefernces\SharpSNMP\SharpSnmpLib.dll' C:\Projects\Project1\CheckerStore.cs 17 21
Note, I did not do anything with the new library, just added as a reference. Any ideas?
The library for some reason re-implements some system types. Likely reason is to make code to be source level compatible when using older versions of the framework.
Most likely there is a version of this SharpSNMP library that works with 4.0 framework. Check if you already have correct on in your source tree. Check with creators of the library what versions of the assembly you need to use with given framework version and what is recommended way of doing it.
You can solve this problem by specifying an external alias. Select the SharpSNMP reference in your project. In the properties window change
Aliases
fromglobal
to saySharpSNMP
. In your code type thisor
See Aliases: overcoming name conflicts part 2: extern alias
What you can do is either change the target version to 3.5 or make some changes in the SharpSNMPLib. The source can be fetched from here or here.
The changes you need to make is specifically moving the System.Tuple type somewhere else.
Edit:
I belive you have added a reference to a precomplied DLL. A DLL that is NOT compiled for framework version 4. What you need to do is download the source code (see links above) and compile the project with target version 4.
Why you need to do this is because there are conditional build parameters depending on the framework target version. The SharpSNMPLib System.Tuple is used for version <= 3.5 and the framework System.Tuple is used for version >= 4.
Edit:
Reproduced your problem using framework System.Tuple and SharpSNMPLib.dll.
Successfully built SharpSNMPLib targeted on version 4.
Successfully built application using framework System.Tuple and the new SharpSNMPLib.dll.
Simply go to your
CheckerStore.cs
file, line 1721 (if I'm right). Find theTuple
class, and reference it using it's fully qualified name.