1

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?

Lex Li
  • 60,503
  • 9
  • 116
  • 147
Tom
  • 3,899
  • 22
  • 78
  • 137
  • Evidently `SharpSNMP` provides their own implementation of that type that is colliding with the system provided one. (probably for backwards compatibility) Do you have the option of not referencing `SharpSnmpLib.dll`? – Kirk Woll May 31 '12 at 21:16
  • No, I must reference it, I need it to implement a new feature of my project. – Tom May 31 '12 at 21:17
  • Which version are you using? Even better, can you provide the URL to the download? – Kirk Woll May 31 '12 at 21:27
  • Thx. This is the download link: http://sharpsnmplib.codeplex.com/downloads/get/316104 – Tom May 31 '12 at 21:29
  • Yep, those types are in that dll and the author provides no other implementation for .NET 4.0. Not sure what the author is thinking, but you could always download the project, rip out that folder, and build your own dlls. – Kirk Woll May 31 '12 at 21:38
  • Then why they say here http://sharpsnmplib.codeplex.com/ .net 4 is supported. OK, I know I should ask them. Bad news, it is not easy to compile – Tom May 31 '12 at 21:39

4 Answers4

8

You can solve this problem by specifying an external alias. Select the SharpSNMP reference in your project. In the properties window change Aliases from global to say SharpSNMP. In your code type this

extern alias SharpSNMP;

...

System.Tuple<T1,T2> sysTulpe;
SharpSNMP::System.Tuple<T1,T2> sharpTulpe;

or

extern alias SharpSNMP;

using SharpSystem = SharpSNMP::System;

...

System.Tuple<T1,T2> sysTulpe;
SharpSystem.Tuple<T1,T2> sharpTulpe;

See Aliases: overcoming name conflicts part 2: extern alias

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
  • Will not work since SharpSNMPLib tuples are not exactly the same as Framework 4 Tuples. – Sani Huttunen May 31 '12 at 21:43
  • 1
    @SaniHuttunen: You may be right that they don't work the same way; however, this is not the point here. It's about resolving the namespace clash. The OP can choose the `Tuple` variant that he wants. – Olivier Jacot-Descombes May 31 '12 at 21:54
  • Yes he can. However if he already extensively uses the framework System.Tuple and decides to alias to SharpSNMPLib Systen.Tuple he has some rewriting to do. – Sani Huttunen May 31 '12 at 22:05
6

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.

Sani Huttunen
  • 23,620
  • 6
  • 72
  • 79
  • 1
    I don't understand. They say SNMP Library supports .net 4: "Support .NET Framework 3.5 SP1, 4.0, .NET Compact Framework 3.5, and Mono 2.8+." http://sharpsnmplib.codeplex.com/ in the middle of the page – Tom May 31 '12 at 21:37
  • 1
    +1. This is the advantage of open souce software; however, don't forget to document all your changes to the library, since you might want do use a more recent version of it in future and you will have to make these changes again. – Olivier Jacot-Descombes May 31 '12 at 22:34
1

Simply go to your CheckerStore.cs file, line 1721 (if I'm right). Find the Tuple class, and reference it using it's fully qualified name.

Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
1

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.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179