473,320 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Late binding equivalent for the .Net class librarys...

..Net is great for modulerising libraries, so that all you need do to access
a DLL, is simply call Add Reference and wallah, it's as though the library
were written in your project.

But what happens when i know that a library must have some method, say

void StoreXML ( string XMLmsg )

but want to late bind, as in, only at run time, decide which library i wish
to use.

COM allows you to design a standard interface, and then any object
implementing that interface can be called by an application using that
standard. It's great for being able to add "plug-in" type technology, having
DLL's there and ready to use, without going back and recompiling your
original application.

Is this sort of thing possible with the .Net Class Librarys?

I've googled a bit buy can't find anything talking about what I'm trying to
do...

Thanks for your time.
Daniel.
Nov 15 '05 #1
5 1538
You can obtain late binding in .NET by using Reflection. For example, I want
to invoke the TestMe method on an object type.

object o;
string methodName = "TestMe";

System.Reflection.MethodInfo mi = o.GetType().GetMethod("TestMe");
mi.Invoke(o,new object[] {});
--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
"Daniel Bass" <I'm really @ sick of spam> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
.Net is great for modulerising libraries, so that all you need do to access a DLL, is simply call Add Reference and wallah, it's as though the library
were written in your project.

But what happens when i know that a library must have some method, say

void StoreXML ( string XMLmsg )

but want to late bind, as in, only at run time, decide which library i wish to use.

COM allows you to design a standard interface, and then any object
implementing that interface can be called by an application using that
standard. It's great for being able to add "plug-in" type technology, having DLL's there and ready to use, without going back and recompiling your
original application.

Is this sort of thing possible with the .Net Class Librarys?

I've googled a bit buy can't find anything talking about what I'm trying to do...

Thanks for your time.
Daniel.

Nov 15 '05 #2
Thanks for that, but I don't see how this binds to the object sitting in
another DLL...

MSDN library uses this GetMethod in a slightly differing context.

Dan

"Jan Tielens" <ja*@no.spam.please.leadit.be> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
You can obtain late binding in .NET by using Reflection. For example, I want
to invoke the TestMe method on an object type.

object o;
string methodName = "TestMe";

System.Reflection.MethodInfo mi = o.GetType().GetMethod("TestMe");
mi.Invoke(o,new object[] {});
--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
"Daniel Bass" <I'm really @ sick of spam> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
.Net is great for modulerising libraries, so that all you need do to access a DLL, is simply call Add Reference and wallah, it's as though the library
were written in your project.

But what happens when i know that a library must have some method, say

void StoreXML ( string XMLmsg )

but want to late bind, as in, only at run time, decide which library i wish to use.

COM allows you to design a standard interface, and then any object
implementing that interface can be called by an application using that
standard. It's great for being able to add "plug-in" type technology, having DLL's there and ready to use, without going back and recompiling your
original application.

Is this sort of thing possible with the .Net Class Librarys?

I've googled a bit buy can't find anything talking about what I'm trying to do...

Thanks for your time.
Daniel.


Nov 15 '05 #3
Why not simply derive all your objects from a given interface, maybe
ISaveAsXml?
"Daniel Bass" <I'm really @ sick of spam> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
Thanks for that, but I don't see how this binds to the object sitting in
another DLL...

MSDN library uses this GetMethod in a slightly differing context.

Dan

"Jan Tielens" <ja*@no.spam.please.leadit.be> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
You can obtain late binding in .NET by using Reflection. For example, I want to invoke the TestMe method on an object type.

object o;
string methodName = "TestMe";

System.Reflection.MethodInfo mi = o.GetType().GetMethod("TestMe");
mi.Invoke(o,new object[] {});
--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
"Daniel Bass" <I'm really @ sick of spam> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
.Net is great for modulerising libraries, so that all you need do to

access
a DLL, is simply call Add Reference and wallah, it's as though the library were written in your project.

But what happens when i know that a library must have some method, say

void StoreXML ( string XMLmsg )

but want to late bind, as in, only at run time, decide which library i

wish
to use.

COM allows you to design a standard interface, and then any object
implementing that interface can be called by an application using that
standard. It's great for being able to add "plug-in" type technology,

having
DLL's there and ready to use, without going back and recompiling your
original application.

Is this sort of thing possible with the .Net Class Librarys?

I've googled a bit buy can't find anything talking about what I'm trying

to
do...

Thanks for your time.
Daniel.


Nov 15 '05 #4
I'm doing that already...
I've created a simple "calculator" application to work this out.

given to numbers, and a Calculate method, i've designed an interface as so:
[in OperationInterface.dll]

namespace Operation
{
public interface IOperation
{
int Calculate ( int a, int b );
}
}

now for each operation, I derive from it, for example
[in Addition.dll]

namespace Operation
{
public class Addition : IOperation
{
public Addition()
{
}

public int Calculate ( int a, int b )
{
return a + b;
}
}
}
now in my main application, calcultar i add a reference to the
OperationInterface.dll so I can see the interface.
How do I get an implementation of an object? (say the addition class).

i've just the reflection.methodinfo approach, as well as
Activator.CreateInstance, but i just get null objects back on the references
in question.

I must admit, I'm sure I'm overlooking it and it's simple (as you probably
know, and I'm yet to discover) but surely this should have been more of a
priority ( or pre-requisite) when creating the model for the .Net class
library's? The idea behind late binding should be right up there with the
drag and dropping of tables from sqlServer (and all connections/commands
being setup etc), and the intellisense etc... It's great to link to .net
library's at design time with a simple "Add Reference" call, shame the it
seems to be a let down in the runtime dept, or is that me just being
cynical. ;o)

thanks for your help.
Dan.
"Daniel O'Connell" <onyxkirx@--NOSPAM--comcast.net> wrote in message
news:ea**************@TK2MSFTNGP09.phx.gbl...
Why not simply derive all your objects from a given interface, maybe
ISaveAsXml?
"Daniel Bass" <I'm really @ sick of spam> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
Thanks for that, but I don't see how this binds to the object sitting in
another DLL...

MSDN library uses this GetMethod in a slightly differing context.

Dan

"Jan Tielens" <ja*@no.spam.please.leadit.be> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
You can obtain late binding in .NET by using Reflection. For example, I want to invoke the TestMe method on an object type.

object o;
string methodName = "TestMe";

System.Reflection.MethodInfo mi = o.GetType().GetMethod("TestMe");
mi.Invoke(o,new object[] {});
--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
"Daniel Bass" <I'm really @ sick of spam> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
.Net is great for modulerising libraries, so that all you need do to

access
a DLL, is simply call Add Reference and wallah, it's as though the library were written in your project.

But what happens when i know that a library must have some method, say

void StoreXML ( string XMLmsg )

but want to late bind, as in, only at run time, decide which library i

wish
to use.

COM allows you to design a standard interface, and then any object
implementing that interface can be called by an application using that
standard. It's great for being able to add "plug-in" type technology,

having
DLL's there and ready to use, without going back and recompiling your
original application.

Is this sort of thing possible with the .Net Class Librarys?

I've googled a bit buy can't find anything talking about what I'm trying

to
do...

Thanks for your time.
Daniel.



Nov 15 '05 #5

"Daniel Bass" <I'm really @ sick of spam> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I'm doing that already...
I've created a simple "calculator" application to work this out.

given to numbers, and a Calculate method, i've designed an interface as so: [in OperationInterface.dll]

namespace Operation
{
public interface IOperation
{
int Calculate ( int a, int b );
}
}

now for each operation, I derive from it, for example
[in Addition.dll]

namespace Operation
{
public class Addition : IOperation
{
public Addition()
{
}

public int Calculate ( int a, int b )
{
return a + b;
}
}
}
now in my main application, calcultar i add a reference to the
OperationInterface.dll so I can see the interface.
How do I get an implementation of an object? (say the addition class).

i've just the reflection.methodinfo approach, as well as
Activator.CreateInstance, but i just get null objects back on the references in question.
Hmm, what code are you using for CreateInstance? Generally
Activator.CreateInstance(TypeName) works(Type name in the form
System.String, mscorlib for example, <type>, <assembly>). You should also be
able to load the given assemblies and enumerate them for types implementing
the given interface:

this is a simple(and untested) example:
using System.Reflection;
using System.Collections;
....
IList objectTypes = new ArrayList();
//fill in your assembly
Assembly asm = Assembly.LoadFile(<assembly>);
Type[] types = asm.GetTypes();
foreach (Type type in types)
{
foreach (Type interfaceType in type.GetInterfaces(0))
{
//fill in your interface type name, if its not ISaveAsXml
if (interfaceType == typeof(ISaveAsXml))
{
objectTypes.Add(interfaceType);
}
}
}
I must admit, I'm sure I'm overlooking it and it's simple (as you probably
know, and I'm yet to discover) but surely this should have been more of a
priority ( or pre-requisite) when creating the model for the .Net class
library's? The idea behind late binding should be right up there with the
drag and dropping of tables from sqlServer (and all connections/commands
being setup etc), and the intellisense etc... It's great to link to .net
library's at design time with a simple "Add Reference" call, shame the it
seems to be a let down in the runtime dept, or is that me just being
cynical. ;o)
Well, reflection is pretty broad, I would suspect you are having specific
issues with it. If you wish to post some sample code, someone will probably
be able to advise you on specifically what. thanks for your help.
Dan.
"Daniel O'Connell" <onyxkirx@--NOSPAM--comcast.net> wrote in message
news:ea**************@TK2MSFTNGP09.phx.gbl...
Why not simply derive all your objects from a given interface, maybe
ISaveAsXml?
"Daniel Bass" <I'm really @ sick of spam> wrote in message
news:uB**************@TK2MSFTNGP12.phx.gbl...
Thanks for that, but I don't see how this binds to the object sitting in
another DLL...

MSDN library uses this GetMethod in a slightly differing context.

Dan

"Jan Tielens" <ja*@no.spam.please.leadit.be> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
You can obtain late binding in .NET by using Reflection. For example, I

want
to invoke the TestMe method on an object type.

object o;
string methodName = "TestMe";

System.Reflection.MethodInfo mi = o.GetType().GetMethod("TestMe");
mi.Invoke(o,new object[] {});
--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
"Daniel Bass" <I'm really @ sick of spam> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
.Net is great for modulerising libraries, so that all you need do to

access
a DLL, is simply call Add Reference and wallah, it's as though the library were written in your project.

But what happens when i know that a library must have some method, say

void StoreXML ( string XMLmsg )

but want to late bind, as in, only at run time, decide which library i

wish
to use.

COM allows you to design a standard interface, and then any object
implementing that interface can be called by an application using that
standard. It's great for being able to add "plug-in" type technology,

having
DLL's there and ready to use, without going back and recompiling your
original application.

Is this sort of thing possible with the .Net Class Librarys?

I've googled a bit buy can't find anything talking about what I'm
trying to
do...

Thanks for your time.
Daniel.



Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JD Kronicz | last post by:
Hi .. I have an issue I have been beating my head against the wall on for some time. I am trying to use late binding for MS graph so that my end users don't have to worry about having the right...
9
by: Zlatko Matić | last post by:
I was reading about late binding, but I'm not completely sure what is to be done in order to adjust code to late binding... For example, I'm not sure if this is correct: early binding: Dim ws...
5
by: Pete | last post by:
Hi, I want to essentially perform late binding in c#. The rough equivalent in VB (6) would be: dim x as ifcMyInterface dim SensibleClassName as string SensibleClassName = .... 'something...
30
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
6
by: Tim Roberts | last post by:
I've been doing COM a long time, but I've just come across a behavior with late binding that surprises me. VB and VBS are not my normal milieux, so I'm hoping someone can point me to a document...
4
by: Rippo | last post by:
Hi I have the following console application and am attempting to late bind a class with option strict on! However of course I cant and I get the following error "Option Strict On disallows late...
9
by: Miro | last post by:
VB 2003 and Im still new to vb, so i hope i can explain this as best I can. I have a variable defined as such: ( simple example ) Dim AVariableOfSorts(,) As Object = _ { _ {"Last", "String",...
6
by: Stephany Young | last post by:
Using VS2005 and VB.NET and given a Windows Forms application with a single form (Form1) with 2 buttons (Button1 and Button2), I am attempting to instantiate an instance of Excel utilising late...
4
by: =?Utf-8?B?Y2xhcmE=?= | last post by:
Hi all, what is the difference between the late binding and reflection? clara -- thank you so much for your help
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.