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

B

b00n1

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
 
B

b00n1

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
 
G

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
 
B

b00n1

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
 

Ask a Question

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. After that, you can post your question and our members will help you out.

Ask a Question

Top