VB.net dll late binding to a vb.net app

Discussion in 'Microsoft VB .NET' started by b00n1, Feb 5, 2007.

  1. b00n1

    b00n1 Guest

    I'm trying to create a simple vb.net (server) dll, and then through
    late binding access the public methods of the contained class from
    another vb.net (client) app. I can do it through early binding. When i
    try late binding it allows me to load the assembly, I can even see the
    methods contained within through reflections, but it fails at the
    point were I try to access the method opencomms or any other method of
    this server class. The error message I get is:

    An unhandled exception of type 'System.NullReferenceException'
    occurred in microsoft.visualbasic.dll

    Additional information: Object variable or With block variable not
    set.

    this is the code in the client app

    windows app calling this routine
    option strinct off

    Public Sub StartContainer()
    Dim SampleAssembly As [Assembly]
    Dim obj As Object

    SampleAssembly = [Assembly].LoadFrom("C:\Protocol\obj\Debug
    \Protocol.dll")

    obj =
    SampleAssembly.CreateInstance("ProtocolFile.ProtocolDll")

    obj.opencomms()

    End Sub

    ProtocolFile.vb complied as Protocol.dll

    Public Class ProtocolDll

    Public Sub OpenComms()
    Console.Write("hello")
    End Sub

    End Class

    Any ideas where I'm going wrong, I can't seem to find any useful
    examples that will give me this anywhere.

    thanks in advance

    Rob
     
    b00n1, Feb 5, 2007
    #1
    1. Advertisements

  2. see the post

    Explicit Linking of DLL's in VB.net



    regards



    Michel

    "b00n1" <> schreef in bericht
    news:...
    > I'm trying to create a simple vb.net (server) dll, and then through
    > late binding access the public methods of the contained class from
    > another vb.net (client) app. I can do it through early binding. When i
    > try late binding it allows me to load the assembly, I can even see the
    > methods contained within through reflections, but it fails at the
    > point were I try to access the method opencomms or any other method of
    > this server class. The error message I get is:
    >
    > An unhandled exception of type 'System.NullReferenceException'
    > occurred in microsoft.visualbasic.dll
    >
    > Additional information: Object variable or With block variable not
    > set.
    >
    > this is the code in the client app
    >
    > windows app calling this routine
    > option strinct off
    >
    > Public Sub StartContainer()
    > Dim SampleAssembly As [Assembly]
    > Dim obj As Object
    >
    > SampleAssembly = [Assembly].LoadFrom("C:\Protocol\obj\Debug
    > \Protocol.dll")
    >
    > obj =
    > SampleAssembly.CreateInstance("ProtocolFile.ProtocolDll")
    >
    > obj.opencomms()
    >
    > End Sub
    >
    > ProtocolFile.vb complied as Protocol.dll
    >
    > Public Class ProtocolDll
    >
    > Public Sub OpenComms()
    > Console.Write("hello")
    > End Sub
    >
    > End Class
    >
    > Any ideas where I'm going wrong, I can't seem to find any useful
    > examples that will give me this anywhere.
    >
    > thanks in advance
    >
    > Rob
    >
     
    Michel Posseth [MCP], Feb 6, 2007
    #2
    1. Advertisements

  3. b00n1

    b00n1 Guest

    Michel

    I've taken a look at this and tried one of your examples creating a
    generic interface compiled to a dll then referenced and implemented in
    the late bound dll, then reference the generic interface in the client
    app, do a directcast as you say and I still get the same result. what
    going on...

    Rob
     
    b00n1, Feb 6, 2007
    #3
  4. b00n1

    Guest Guest

    well it should work like this ( at least it does with me :- )

    < info you have read in the previous post >
    The concept is pretty simple

    1. create a generic interface and compile this to a dll
    2. create your plugin and implement the interface in the class you want to
    start from the outside

    3. create a application and set a reference to the interface dll

    now you do

    Dim objAssembly As Reflection.Assembly
    objAssembly = Reflection.Assembly.LoadFrom(FullPathToAssemblyDllOrExe)

    Dim YourObject as Yourinterface =
    DirectCast(objAssembly.CreateInstance(Namespace.YourClassToInvoke),
    Yourinterface)

    Note :
    Namespace.YourClassToInvoke ( namespace defaults to the assembly name but
    can be set under project , properties , application , root namespace )

    And that`s it !! :)

    YourObject is now initiated and can be controled from your code with the
    interface that you provided
    </info you should have read in the previous post >

    probably something goes wrong here

    example from one of my test projects

    Dim objAssembly As Reflection.Assembly
    objAssembly =
    Reflection.Assembly.LoadFrom("C:\ProgramFiles\ista\NeProS\QueueService\QueuClassTest.dll")

    Dim YourObject as Yourinterface =
    DirectCast(objAssembly.CreateInstance(ista.Test),
    Yourinterface)

    Note the ista. part is the namespace ( you must provide the namespace name )


    I will wrap up a hello world example

    regards

    Michel





    "b00n1" wrote:

    > Michel
    >
    > I've taken a look at this and tried one of your examples creating a
    > generic interface compiled to a dll then referenced and implemented in
    > the late bound dll, then reference the generic interface in the client
    > app, do a directcast as you say and I still get the same result. what
    > going on...
    >
    > Rob
    >
    >
     
    Guest, Feb 6, 2007
    #4
  5. b00n1

    b00n1 Guest

    Michel

    Thanks very much for your time. I was getting the namespace qualifier
    wrong, I was using the filename instead of project name as a
    qualifier. It didn't dawn on me untill I tried early binding and
    noticed the difference. Changed this and hey presto it wrorked.

    Best regards, and thanks again

    Rob
     
    b00n1, Feb 6, 2007
    #5
  6. b00n1

    Guest Guest

    here is a working simple example

    http://www.vbdotnetcoder.com/reflectionexample.rar


    hth

    michel Posseth



    "Michel Posseth [MCP]" wrote:

    > well it should work like this ( at least it does with me :- )
    >
    > < info you have read in the previous post >
    > The concept is pretty simple
    >
    > 1. create a generic interface and compile this to a dll
    > 2. create your plugin and implement the interface in the class you want to
    > start from the outside
    >
    > 3. create a application and set a reference to the interface dll
    >
    > now you do
    >
    > Dim objAssembly As Reflection.Assembly
    > objAssembly = Reflection.Assembly.LoadFrom(FullPathToAssemblyDllOrExe)
    >
    > Dim YourObject as Yourinterface =
    > DirectCast(objAssembly.CreateInstance(Namespace.YourClassToInvoke),
    > Yourinterface)
    >
    > Note :
    > Namespace.YourClassToInvoke ( namespace defaults to the assembly name but
    > can be set under project , properties , application , root namespace )
    >
    > And that`s it !! :)
    >
    > YourObject is now initiated and can be controled from your code with the
    > interface that you provided
    > </info you should have read in the previous post >
    >
    > probably something goes wrong here
    >
    > example from one of my test projects
    >
    > Dim objAssembly As Reflection.Assembly
    > objAssembly =
    > Reflection.Assembly.LoadFrom("C:\ProgramFiles\ista\NeProS\QueueService\QueuClassTest.dll")
    >
    > Dim YourObject as Yourinterface =
    > DirectCast(objAssembly.CreateInstance(ista.Test),
    > Yourinterface)
    >
    > Note the ista. part is the namespace ( you must provide the namespace name )
    >
    >
    > I will wrap up a hello world example
    >
    > regards
    >
    > Michel
    >
    >
    >
    >
    >
    > "b00n1" wrote:
    >
    > > Michel
    > >
    > > I've taken a look at this and tried one of your examples creating a
    > > generic interface compiled to a dll then referenced and implemented in
    > > the late bound dll, then reference the generic interface in the client
    > > app, do a directcast as you say and I still get the same result. what
    > > going on...
    > >
    > > Rob
    > >
    > >
     
    Guest, Feb 6, 2007
    #6
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Guest

    Early Binding v.s. Late Binding

    Guest, Jan 19, 2004, in forum: Microsoft VB .NET
    Replies:
    13
    Views:
    2,366
    Jay B. Harlow [MVP - Outlook]
    Jan 19, 2004
  2. m.posseth
    Replies:
    0
    Views:
    265
    m.posseth
    Jan 30, 2006
  3. Elankathir S.N.

    Event Handling in VB.Net + Late Binding

    Elankathir S.N., Jul 27, 2006, in forum: Microsoft VB .NET
    Replies:
    1
    Views:
    778
    Ken Tucker [MVP]
    Jul 27, 2006
  4. Lynn
    Replies:
    7
    Views:
    535
    Omar Abid
    Jul 14, 2007
  5. Mike

    VB Net/Com Interoperability/Late Binding

    Mike, Jun 26, 2009, in forum: Microsoft VB .NET
    Replies:
    4
    Views:
    735
  6. douglas

    late binding when vb.net 2005 updates excel 2003

    douglas, Jul 14, 2009, in forum: Microsoft VB .NET
    Replies:
    2
    Views:
    580
    Andrew Morton
    Jul 14, 2009
  7. Maciej Franciszkowski

    Late binding error - running Ms Access Report in VB.Net

    Maciej Franciszkowski, Dec 11, 2010, in forum: Microsoft VB .NET
    Replies:
    1
    Views:
    1,543
    Jason Keats
    Dec 12, 2010
  8. The Mad Ape

    VB.NET InputPanel AutoScrolling Late Binding Problem

    The Mad Ape, Feb 15, 2012, in forum: Microsoft VB .NET
    Replies:
    1
    Views:
    778
    The Mad Ape
    Feb 15, 2012
Loading...