29

I have 1 DLL in the .Net 3.5 framework and another in 2.0. The ListBoxItem class exists in 2.0 and I have linked the class in the 3.5 DLL in the same namespace.

When I try to compile I get an "exists in both" error. How can I compile this and maintain the same structure.

I don't want reference the 2.0 DLL to 3.5 to eliminate this problem, I want keep these DLLs separate.

pedrofernandes
  • 16,354
  • 10
  • 36
  • 43

4 Answers4

6

This doesn't seem like a good idea no matter what, but change the namespaces and fully qualify your usages.

Otherwise, why don't you just reference one dll?

Bryan Rowe
  • 9,185
  • 4
  • 26
  • 34
  • If i change namespaces this 2 dlls can't be used in same method because have 2 diferent signatures. – pedrofernandes Jun 29 '09 at 14:56
  • I don't want instance 2.0 dll in 3.5 dll because 2.0 dll have big references added and when i compile it compile my 3.5, 2.0 dlls more all referenced dlls in 2.0, for what i can have 15 dlls when i can have only 2 dlls im my bin folder. – pedrofernandes Jun 29 '09 at 14:56
  • You need to rework the english in the last couple posts. I have no clue what you are saying. Maybe just make it all one dll? – Bryan Rowe Jun 29 '09 at 18:11
  • Sorry for my english :). I resolved the problem myself. I introduced an interface and eliminated the class in framework 3.5, next replaced all references to this class with interface. – pedrofernandes Jun 29 '09 at 22:27
5

This is a relevant solution as well, where you can define which type to use in your usings:

https://stackoverflow.com/a/9194582/178620

You can't use fully qualified names when dealing with Extension methods and etc.

Community
  • 1
  • 1
Doguhan Uluca
  • 6,933
  • 4
  • 38
  • 51
  • 2
    You CAN use fully qualified names to refer to extension methods but only if you call them directly, rather than as and extension. – Ed Bishop Jul 07 '14 at 10:55
3

Old thread but wanted to add in another instance where this issue occurred. Was delaing with a project that was converted from website to web application in Visual Studio 2010. I started to get the type "class" exists in both .../temporary ASP.NET/...yada...yada...yada.

In my case, the old page used a datagrid to display a list of dates but the dataset was a list of classes List<MyClass> and the code in the .aspx (not code behind) was using the methodology of casting the data item for display...

<%# ((MyClass)Container.DataItem).MyDate %>

For some reason, MyClass was triggering the type error. After doing the full search throughout the project for any possible double class references and the like, did not find anything so basically decided to see if I got rid of the cast and just go with standard method of getting the value from the DataItem as follows:

<%# DataBinder.Eval(Container.DataItem, "MyDate").ToString()%>

And voila...no more type exists error. Not too sure why this would cause the above error to manifest itself (and if anyone has any insight, it would be appreciated) but the problem is gone...

Hope this helps someone...

Dave

Dave
  • 740
  • 1
  • 6
  • 17
1

Split them into two different solutions, one for .NET 2.0 and the other for .NET 3.5. Otherwise, how would .NET knows how to load which one?

Adrian Godong
  • 8,802
  • 8
  • 40
  • 62