Link Two DLLs with the same namespaces and types

I have two versions of the same DLL, that is LibV1.dll and LibV2.dll. Both libraries have the same namespaces and types, but are not compatible. I need to be able to reference the VB.Net project at the same time to update the data from the old version to the new one. In C #, this is pretty easy to solve, but everything I read indicates that there is no solution in VB.Net. In fact, I see this post since 2011, which confirms this. I wonder if there were any changes in the last 4 years that could make this possible now?

+4
source share
1 answer

Sorry, I was hoping to insert this comment, but SO does not allow me to do this.

As far as I know, VB did not add the C # merge function, but your statement that there is no solution in VB.Net is incorrect.

2011 Reflection . , , DLL Intellisense DLL. Reflection.Assembly.LoadFile, DLL CreateInstance Object . . Reflection, MethodInfo/PropertyInfo/etc. , , , , .

.

Sub Test()
    ' assume you chose Version 2 as to reference in your project
    ' you can create an instance of its classes directly in your code 
    ' with full Intellisense support

    Dim myClass1V2 As New CommonRootNS.Class1

    ' call function Foo on this instance
    Dim resV2 As Int32 = myClass1V2.foo

    ' to get access to Version 1, we will use Reflection to load the Dll

    ' Assume that the Version 1 Dll is stored in the same directory as the exceuting assembly
    Dim path As String = IO.Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly.Location)

    Dim dllVersion1Assembly As Reflection.Assembly
    dllVersion1Assembly = Reflection.Assembly.LoadFile(IO.Path.Combine(path, "Test DLL Version 1.dll"))

    ' now create an instance of the Class1 from the Version 1 Dll and store it as an Object
    Dim myClass1V1 As Object = dllVersion1Assembly.CreateInstance("CommonRootNS.Class1")

    ' use late binding to call the 'foo' function. Requires Option Strict Off
    Dim retV1 As Int32 = myClass1V1.foo
End Sub
+2

All Articles