PC Review


Reply
Thread Tools Rate Thread

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

 
 
b00n1
Guest
Posts: n/a
 
      6th Feb 2007
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

 
Reply With Quote
 
 
 
 
Michel Posseth [MCP]
Guest
Posts: n/a
 
      6th Feb 2007
see the post

Explicit Linking of DLL's in VB.net



regards



Michel

"b00n1" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
b00n1
Guest
Posts: n/a
 
      6th Feb 2007
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

 
Reply With Quote
 
=?Utf-8?B?TWljaGVsIFBvc3NldGggW01DUF0=?=
Guest
Posts: n/a
 
      6th Feb 2007
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
>
>

 
Reply With Quote
 
b00n1
Guest
Posts: n/a
 
      6th Feb 2007
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

 
Reply With Quote
 
=?Utf-8?B?TWljaGVsIFBvc3NldGggW01DUF0=?=
Guest
Posts: n/a
 
      6th Feb 2007

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
> >
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
>> Early binding and late binding with attachment =?Utf-8?B?Sm9uYXRoYW4=?= Microsoft Outlook VBA Programming 2 9th Jun 2006 02:24 AM
Late Binding or Late Anything Piranha Microsoft Excel Programming 4 15th Oct 2005 03:42 AM
Late Binding examples of binding excel application =?Utf-8?B?SGVhdGhlck8=?= Microsoft Excel Programming 14 17th Mar 2005 09:19 AM
EARLY binding or LATE binding ? jason Microsoft Excel Programming 6 26th Feb 2004 05:57 PM
Early Binding v.s. Late Binding =?Utf-8?B?Q2hyaXMgQWRhbXM=?= Microsoft VB .NET 13 19th Jan 2004 04:47 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:48 AM.