473,473 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Late Binding an Interface

How can i load an interface from a dll using System.Reflection?

I can see how its possible to do this on methods, properties in a class. You
create an instance of the class and use the invoke method.

Type t = Type.GetType("MyAssembly.MyClass");
Object obj1 = Activator.CreateInstance(t);
obj1.GetType().InvokeMember("MyMethod",BindingFlag s.Default,null,obj1,new
object[]{});

But you cannot create instances of interfaces, so how can you late bind
methods/properties in an interface....?

thanks


An interface however cannot create instances, so
Nov 17 '05 #1
5 5054
I am not sure what your asking. Could you elaborate more.

You can't create instances of interfaces. You can create instances of
classes that implement interfaces. And you can get the the interface from a
class instance.

For example, (from your example)

Type myType = Type.GetType("MyAssembly.MyClass");
IMyInterface myInterface = Activator.CreateInstance(myType) as
IMyInterface;
myInterface.DoThatVoodoo(thatYouDo, soWell);

Does this help?

Frisky

"CodeRazor" <Co*******@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
How can i load an interface from a dll using System.Reflection?

I can see how its possible to do this on methods, properties in a class.
You
create an instance of the class and use the invoke method.

Type t = Type.GetType("MyAssembly.MyClass");
Object obj1 = Activator.CreateInstance(t);
obj1.GetType().InvokeMember("MyMethod",BindingFlag s.Default,null,obj1,new
object[]{});

But you cannot create instances of interfaces, so how can you late bind
methods/properties in an interface....?

thanks


An interface however cannot create instances, so

Nov 17 '05 #2
Hi,

AFAIK this is not possible, what do you want to do?

An interface is like the opposite of what you want to do, with an interface
you are early binding the methods/properties an instance will have, with
late binding/reflection you just "discover" the interface at runtime.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"CodeRazor" <Co*******@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
How can i load an interface from a dll using System.Reflection?

I can see how its possible to do this on methods, properties in a class.
You
create an instance of the class and use the invoke method.

Type t = Type.GetType("MyAssembly.MyClass");
Object obj1 = Activator.CreateInstance(t);
obj1.GetType().InvokeMember("MyMethod",BindingFlag s.Default,null,obj1,new
object[]{});

But you cannot create instances of interfaces, so how can you late bind
methods/properties in an interface....?

thanks


An interface however cannot create instances, so

Nov 17 '05 #3
myInterface.DoThatVoodoo(thatYouDo, soWell);


this cracked me up.
Nov 17 '05 #4
....therin lies my answer!! thank you, everyone.

I was skipping a step, that's why i was having problems. What i need to do
is to perform late binding on a class that implements my interface.

aha!

Nov 17 '05 #5
CodeRazor,

If you have a reference to the interface definition, then you can create
an instance of your type (through the Activator class) and then just cast
the instance to the interface type. For this reason, the interface types
are usually defined in an assembly outside of the implementation, so that it
can be shared by the implementation, and the code using the implementation.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"CodeRazor" <Co*******@discussions.microsoft.com> wrote in message
news:7C**********************************@microsof t.com...
...therin lies my answer!! thank you, everyone.

I was skipping a step, that's why i was having problems. What i need to do
is to perform late binding on a class that implements my interface.

aha!

Nov 17 '05 #6

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

Similar topics

0
by: mia lanui | last post by:
I have 3 C#.NET assemblies: Assembly A: Calls methods of Assembly C, which implements an interface in Assembly B, therefore, must reference both B and C (unless late binding is used) Assembly...
5
by: Daniel Bass | last post by:
..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...
9
by: Scott English | last post by:
I am writing an C# program. I call a method on a COM object that returns Object. I don't know the type of the object (and reflection just says its a __ComObject), but I know there is supposed to...
1
by: Jim | last post by:
Hey all I'm trying to late bind a VB6 object in Component Services using c#. I've been able to do tons of late binding, but now that I have a com+ object that doesn't have a method exposed...
2
by: cmrchs | last post by:
Hi, is it possible to instantiate an object on a remote server using late-binding ? (so the client does not need the info at compile time.) I look at remoting, but all those methods 'force'...
9
by: John Smith | last post by:
Hey, I'm having a difficult time finding some good examples of late binding Outlook in C#. Anyone know of any good sites out there? I've googled and MSDN'ed, but have come up a bit empty. ...
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...
2
by: Wonder | last post by:
Hi all, I have two objects in my COM+ that I can't add the references to my project. It has to use late binding in C#. For my applications in vb.net, I can solve the problem using the code...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.