esjr
esjr

Reputation: 186

How to access C# members that differ in case from inside a vb.net project

This :

public class Something
{
    public string lala = "";

    public class Lala
    {
         //...
    }
}

is legal C# now I compile it etc and drop the dll in a new Vb.Net project : how do I access member lala from VB.Net, if I try I get the error "'lala' is ambiguous because multiple kinds of members with this name exist in class Something".

Upvotes: 0

Views: 178

Answers (2)

Dave Doknjas
Dave Doknjas

Reputation: 6542

Unfortunately, you're probably going to have to resort to reflection to access this dll. Once you get your System.Type instance for the 'Something' class (using the 'GetType' instance method of the System.Reflection.Assembly type), you will use the type instance's 'GetField' method to access the 'lala' field and the type instance's 'GetNestedType' method to access the 'Lala' nested type.

Imports System.Reflection
...
Dim assembly As Assembly = Assembly.Load(...)
Dim outerType As Type = assembly.GetType("Something")
Dim field As FieldInfo = outerType.GetField("lala")
Dim nestedType As Type = outerType.NestedType("Lala")

You would then use field.SetValue(..) and field.GetValue(..) to access the 'lala' field.

Upvotes: 1

user153923
user153923

Reputation:

First: Add the reference to your project.

add reference

Browse to your Something_Lala DLL file and add it.

Next, you need to import that into your file, initialize it, and then use it.

psudo code

The example code looks bad, but that was all you gave the SO community to work with.

Upvotes: 1

Related Questions