Blog Stats
  • Posts - 42
  • Articles - 0
  • Comments - 61
  • Trackbacks - 36

 

Dynamically loading a C# serviced component

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();


Feedback

# re: Dynamically loading a C# serviced component

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"); 9/20/2005 7:35 PM | Luke

# re: Dynamically loading a C# serviced component

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 9/21/2005 7:40 AM | Vinayak

Post a comment





 

 

 

Copyright © Vinayak