C# assembly functions with same name differ by case accessed in vb.net code / Access C# code in Vb.net code

As we all know C# in case sensitive langauage and vb.net case in-sensitive language. also its been known fact that we can able to access the assembly created in one language supported by .Net (e.g. C#) in another langauge code (VB.net) , can use functions in that assembly.

So here we are going to consider a classic case of accessing 2 functions with same name which are differ in case accessed in vb.net
Suppose we are having one assembly created in C# with 2 functions functionOne() and FUNCTIONone()
when we are accessing in vb.net as it is case-insensitive we as function name is same it should be treated as single name and when try to access any if these 2 functions in this assembly it will give us
‘Overload Resolution failed error ‘ bcoz for vb.net compiler if single function with two diff implementation!!!!
, but in this case .net framework provided us some functionality – one namespace to access these functions seperately – using
System.Reflection & InvokeMember() method of the GetType() of the current class instance.

for e.g. we are going to create one sample dll / assembly in C# as follows
namespace Call2Methods
{

public class MyClass
{
public string functionOne()
{
return “Method1”;
}

public string FUNCTIONone()
{
return “Method2”;
}
}
}

so after this created dll , we are going to use this in vb.net code as follows

Dim MyClass As New Call2Methods.MyClass
Dim GetReturnValue =
MyClass .GetType.InvokeMember(“FUNCTIONone”,System.Reflection.BindingFlags.Instance Or BindingFlags.Public Or BindingFlags.InvokeMethod,Nothing, MyClass , Nothing, Nothing, Nothing, Nothing)

OR

Dim MyClass As New Call2Methods.MyClass
Dim GetReturnValue =
MyClass .GetType.InvokeMember(“functionOne”,System.Reflection.BindingFlags.Instance Or BindingFlags.Public Or BindingFlags.InvokeMethod,Nothing, MyClass , Nothing, Nothing, Nothing, Nothing)

Advertisements

One thought on “C# assembly functions with same name differ by case accessed in vb.net code / Access C# code in Vb.net code”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s