Results 1 to 5 of 5

Thread: [RESOLVED] Problem using a dll written in VB in C#

  1. #1

    Thread Starter
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    Resolved [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:
    1. Assembly a = Assembly.LoadFrom("my_dll.dll");
    2. foreach (Type t in a.GetTypes())
    3. {
    4.     ...
    5. }
    and for some reason it never goes through that foreach.
    Do you have any suggestions? Thank you.
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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

  3. #3
    New Member
    Join Date
    May 2006
    Posts
    15

    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.

  4. #4

    Thread Starter
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    Re: Problem using a dll written in VB in C#

    I'm trying to invoke it like this:
    VB Code:
    1. Assembly a = Assembly.LoadFrom(s);
    2.             Object calc = new object();
    3.             MethodInfo mi = null;
    4.             string mtname= "FormName";
    5.             MessageBox.Show(a.GetTypes().Length.ToString());  // i get 20 here
    6.             foreach (Type t in a.GetTypes())
    7.             {
    8.                 Console.WriteLine("name=\t" + t.Name);
    9.                 if (t.Name.Equals(mtname))
    10.                 {
    11.                     Console.WriteLine("ura");
    12.                     if (mtname.Equals("FormName"))
    13.                     {
    14.                         try
    15.                         {
    16.                             calc = Activator.CreateInstance(t);
    17.                         }
    18.                         catch (Exception exc)
    19.                         {
    20.                             MessageBox.Show(exc.ToString());
    21.                         }
    22.                         MethodInfo[] ms = t.GetMethods();
    23.                         int i = 0;
    24.                         for (i = 0; i < ms.Length; i++)
    25.                             Console.WriteLine("METODA:\t" + ms[i].Name);
    26.                         mi = t.GetMethod("New");
    27.                         break;
    28.                     }
    29.             try
    30.             {
    31.                 Console.WriteLine("inainte sa invoc ");
    32.                 mi.Invoke(calc, null);   // here i get System.NullReferenceException:
    33.                                          // Object not set to an instance of an object. (mi is null)
    34.                 Console.Out.WriteLine("am invocat");
    35.             }
    36.             catch (Exception e)
    37.             {
    38.                 MessageBox.Show(e.ToString());
    39.             };
    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.
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

  5. #5

    Thread Starter
    Addicted Member zahadumy's Avatar
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    187

    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.
    The first step in solving a problem is to define the problem clearly.

    -----
    Icons | EZIconConverter | Popup Messages
    101 samples: 2003 2005
    Code converter: C# -> VB .NET | VB .NET -> C# | VB .NET <-> C#


    -----
    Visual Studio 2005/.NET Framework 2.0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width