Paul Michaels
Paul Michaels

Reputation: 16695

Namespaces in .net

I thought I knew the answer to this, but a compile error is telling me different. I have created two separate libraries which contain the same stem namepsace; for example:

MyLib1.dll 

contains

Common.MyFuncs.DoSomeStuff

And

MyLib2.dll

contains

Common.MyFuncs.DoOtherStuff

MyLib2.dll references myLib1.dll

When I include references to both in my project, MyLib1.dll is masking MyLib2.dll. My question is simply, is this correct - i.e. is this what .net does? I know it's possible to use extern for conflicting namepsaces, but I'm sure that I've seen namespaces shared across assemblies before (in fact, I'm sure that I've done it before), but I can't seem to find anything online to indicate I'm right or wrong.

Upvotes: 0

Views: 51

Answers (1)

slugster
slugster

Reputation: 49984

Namespaces don't "mask" each other, the same namespace can quite happily co-exist in multiple assemblies (in fact there are some System.* namespaces that exist across multiple assemblies). Are you sure that you don't have the same types defined in each assembly (maybe you've moved code but didn't rememove the original?), that way you won't get collisions between your types.

When you reference both projects, you still need to include a using Common.MyFuncs.[whatever]; statement at the top of each code file that needs to use the types from it.

Upvotes: 1

Related Questions