Geeks With Blogs
finally{} My interactions with .Net and Web development - What's most important is what happens finally{}
Type type = Type.GetTypeFromProgID( "ComponentName.1", "localhost", true );
// or, using a guid....
//Type type = Type.GetTypeFromCLSID( new Guid( "{AA77B197- A85D-445E-88C9-2A564D756220}" ), "remoteserver", false );

m_Component = (IMyInterface) Activator.CreateInstance( type );
// IMyInterface is the interface that is extended by the serviced component on the server side.
//Now call any method on the component.
m_Component.ComponentsMethod();

Posted on Tuesday, September 20, 2005 4:26 PM .Net Framework , C# | Back to top


Comments on this post: Dynamically loading a C# serviced component

# re: Dynamically loading a C# serviced component
Requesting Gravatar...
Sometimes I want to do this when the assembly for the serviced component is not present in the GAC or locally, so the type cannot be loaded. And why should it have to be, when all you need is the interface? Then the trick is to do this:

m_Component = (IMyInterface) Marshal.BindToMoniker("new:ComponentName.1");
Left by Luke on Sep 20, 2005 7:35 PM

# re: Dynamically loading a C# serviced component
Requesting Gravatar...
Thanks for the info. But then, if its not in GAC, neither locally, then where is the assembly located in your scenario? and what about the "new:" new and colon thing that you've specified?

Could you please clarify more.

Thanks,
Vinayak
Left by Vinayak on Sep 21, 2005 7:40 AM

Your comment:
 (will show your gravatar)


Copyright © Vinayak | Powered by: GeeksWithBlogs.net