Use types of same name & namespace in 2 .NET assemblies

久未见 提交于 2019-11-29 13:15:54
CMS

I think you should use an extern alias to wrap the assembly namespaces outside of the Global namespace. Here's how:

  1. In the project that references the 2 assemblies, select one of them under References, and in the Properties window change the Aliases value from global to, say, global, Library1a.

  2. Do the same for the the other reference, but give it a different alias-- let's go with global, Library1b for our example.

  3. Insert extern alias Library1a; and/or extern alias Library1b; as the first 2 lines of any classes that consume the assemblies.

  4. When accessing ambiguous members, qualify the namespace with Library1a. or Library1b.. Examples: Library1a.Library1.Class1... Library1b.Library1.Class1...

sipwiz

It happens in practice and is a real pain, the external alias can't always solve the problem. Here's one example of where it's an issue Duplicate Namepsaces.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!