MrEyes
MrEyes

Reputation: 13680

.NET - Multiple libraries with the same namespace - referencing

Today I am faced with a curious challenge...

This challenge involves two .NET libraries that I need to reference from my application. Both of which I have no control over and have the same namespace within them.

So...

I have foo.dll that contains a Widget class that is located on the Blue.Red.Orange namespace.

I have bar.dll that also contains a Widget class that is also located on the Blue.Red.Orange namespace.

Finally I have my application that needs to reference both foo.dll and bar.dll. This is needed as within my application I need to use the Widget class from foo and also the Widget class from bar

So, the question is how can I manage these references so that I can be certain I am using the correct Widget class?

As mentioned, I have no control over the foo or bar libraries, they are what they are and cannot be changed. I do however have full control over my application.

Upvotes: 24

Views: 14962

Answers (5)

Jon Skeet
Jon Skeet

Reputation: 1499770

You need to use an extern alias - introduced in C# 2.

Anson Horton has a walkthrough on his blog which you may find useful.

Upvotes: 45

AbrahamJP
AbrahamJP

Reputation: 3430

You could use the "Aliases" property for resolving conflicts. Select the library and open Property window. This is already discussed in this SO post

Upvotes: 1

Tom B
Tom B

Reputation: 2180

I think you have to use extern alias

See http://msdn.microsoft.com/en-us/library/ms173212.aspx

Here's a walkthrough. http://blogs.msdn.com/b/ansonh/archive/2006/09/27/774692.aspx

Upvotes: 8

Alexander Schmidt
Alexander Schmidt

Reputation: 5723

Wow, thats tricky. I tink, I would create two wrapper-DLLs:

  1. MyBarWrapper.dll (which has a reference to bar.dll)
  2. MyFooWrapper.dll (which has a reference to foo.dll)

and support different namespaces there.

Upvotes: 0

Massif
Massif

Reputation: 4433

I'd be surprised if you can do this, without using reflection.

It might be easier to create your own FooWrapper and BarWrapper dlls which reference foo and bar and expose their contents again under different namespaces.

Upvotes: -1

Related Questions