[RESOLVED] Problem using a dll written in VB in C#
I have a dll written in VB and I'm trying to do something like this:
VB Code:
Assembly a = Assembly.LoadFrom("my_dll.dll");
foreach (Type t in a.GetTypes())
{
...
}
and for some reason it never goes through that foreach.
Do you have any suggestions? Thank you.
Re: Problem using a dll written in VB in C#
What do you want to accomplish here by late binding? Why not just reference the class library in your solution?
Also, step through the code. Do you get any errors or messages?
Have a look here and see if this helps.
http://www.vbforums.com/showthread.p...ght=Reflection
Re: Problem using a dll written in VB in C#
Why don't your try these two things.
Code:
Type typeObjects[] = a.GetExportedTypes();
foreach (Type t in typeObjects)
{
}
And when you load the assembly, pass it's fully qualified assembly name.
Re: Problem using a dll written in VB in C#
I'm trying to invoke it like this:
VB Code:
Assembly a = Assembly.LoadFrom(s);
Object calc = new object();
MethodInfo mi = null;
string mtname= "FormName";
MessageBox.Show(a.GetTypes().Length.ToString()); // i get 20 here
foreach (Type t in a.GetTypes())
{
Console.WriteLine("name=\t" + t.Name);
if (t.Name.Equals(mtname))
{
Console.WriteLine("ura");
if (mtname.Equals("FormName"))
{
try
{
calc = Activator.CreateInstance(t);
}
catch (Exception exc)
{
MessageBox.Show(exc.ToString());
}
MethodInfo[] ms = t.GetMethods();
int i = 0;
for (i = 0; i < ms.Length; i++)
Console.WriteLine("METODA:\t" + ms[i].Name);
mi = t.GetMethod("New");
break;
}
try
{
Console.WriteLine("inainte sa invoc ");
mi.Invoke(calc, null); // here i get System.NullReferenceException:
// Object not set to an instance of an object. (mi is null)
Console.Out.WriteLine("am invocat");
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
};
Do you have any idea where am I going wrong? I saw very similar code in your link. Thank you.
Re: Problem using a dll written in VB in C#
Problem solved.
Instead of this line:
Code:
mi = t.GetMethod("New");
i needed this one:
Code:
mi = t.GetMethod("start");
where start() is a new sub in my dll and looks like this:
Code:
Public Sub start()
Application.Run(New FormName())
End Sub
in case someone will ever read this... :)
Thank you guys.