Using two .NET libraries with the same namespace

可紊 提交于 2020-01-03 15:54:21

问题


I'm currently maintaining some old code for a company. As it would happen, the current app I'm modifying uses an older version of the in-house library (we'll call this Lib1.dll). They also have a new version of the library called Lib2.dll that improves upon the previous library in many ways.

Unfortunately, Lib2 is not backward compatible with Lib1. What's worse is that they both use the same namespace Product.Common.

How do I use Lib2 and Lib1 in the same project? Right now if I add references to both of them, VS tells me that certain classes are ambiguous (which makes sense, since they using the same namespace).

Basically, I need something like:

Imports Lib1:Product.Common.Class

I'm using VB.NET 1.1.


回答1:


I found a blog entry that has a solution in C#, not sure of the solution in VB.NET.

Extern alias walkthrough and C# 2.0: Using different versions of the same dll in one application


Edit:

It would seem you are out of luck. There does not appear to be a solution with .NET 1.1.




回答2:


You could add another project to "host" one of your Lib projects. Basically just add a layer to nest the namespace a level deeper so it no longer causes a conflict.




回答3:


If Lib2.dll improves over Lib1.dll, why do you still need Lib1.dll? The best thing to do is remove Lib1.dll from your project and just use Lib2.dll.

if not, try this link and see if that helps

http://blogs.msdn.com/ansonh/archive/2006/09/27/774692.aspx




回答4:


I think Joel's answer is probably the easiest approach. But another more extreme option would be to run the program through ildasm, do a search replace on the namespace, and run the result through ilasm.

You could run into other issues, such as signing, with this approach, but it would allow you to "rename" the namespace in the assembly.



来源:https://stackoverflow.com/questions/740991/using-two-net-libraries-with-the-same-namespace

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