|
-
May 30th, 2006, 10:26 AM
#1
Thread Starter
Addicted Member
[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.
-
May 30th, 2006, 05:59 PM
#2
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
-
May 30th, 2006, 06:38 PM
#3
New Member
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.
-
May 30th, 2006, 06:53 PM
#4
Thread Starter
Addicted Member
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.
Last edited by zahadumy; May 30th, 2006 at 07:07 PM.
-
May 30th, 2006, 08:46 PM
#5
Thread Starter
Addicted Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|