Executing COM+ class

  • Thread starter Thread starter Slavan
  • Start date Start date
S

Slavan

I am trying to execute following code:

Type type = Type.GetTypeFromProgID("SomeType.SomeClass", true);
object helper = Activator.CreateInstance(type);

and get following RemotingException (in 2-nd line):

Cannot load type SomeType.SomeClass, SomeType.SomeClass,
Version=1.0.2658.25296, Culture=neutral, PublicKeyToken=null

There is no other info why it breaks. I can't figure out what is going
wrong.
SomeType.SomeClass is installed as a COM+ component. I checked "type"
for null and it's not null.
Any help would be appreciated.
 
Slavan,

Is SomeType.SomeClass a .NET component? If so, you need to have a
reference to the original assembly and create the type using the new
keyword. .NET components hosted in COM+ can not be created in .NET through
COM interop (which is essentially what you are trying to do, if this is the
case).

Hope this helps.
 
Slavan,

Is SomeType.SomeClass a .NET component? If so, you need to have a
reference to the original assembly and create the type using the new
keyword. .NET components hosted in COM+ can not be created in .NET through
COM interop (which is essentially what you are trying to do, if this is the
case).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)




I am trying to execute following code:
Type type = Type.GetTypeFromProgID("SomeType.SomeClass", true);
object helper = Activator.CreateInstance(type);
and get following RemotingException (in 2-nd line):
Cannot load type SomeType.SomeClass, SomeType.SomeClass,
Version=1.0.2658.25296, Culture=neutral, PublicKeyToken=null
There is no other info why it breaks. I can't figure out what is going
wrong.
SomeType.SomeClass is installed as a COM+ component. I checked "type"
for null and it's not null.
Any help would be appreciated.- Hide quoted text -

- Show quoted text -

Thanks for reply, SomeType.SomeClass is indeed a .NET component hosted
as COM+ class.
Is there any other way to use it. I don't want to create a reference
to dll, since it's location will be unknown at install?
 
You could try running FUSLOGVW (the Fusion Log Viewer) from a Visual Studio
Command Prompt to capture a trace of the process that your program is doing
while trying to locate the DLLs. This could give you a clue as to what is
missing. For instance, maybe the component is registered in COM+, but the
..Net assembly is neither in the GAC nor in a folder that is searched by the
fusion process. Indeed, looking at the error "Version=1.0.2658.25296, ...
PublicKeyToken=null", it looks like the assembly does not have a strong
name, and therefore it can't be in the GAC.
 
Slavan said:
I am trying to execute following code:

Type type = Type.GetTypeFromProgID("SomeType.SomeClass", true);
object helper = Activator.CreateInstance(type);

and get following RemotingException (in 2-nd line):

Cannot load type SomeType.SomeClass, SomeType.SomeClass,
Version=1.0.2658.25296, Culture=neutral, PublicKeyToken=null

There is no other info why it breaks. I can't figure out what is going
wrong.
SomeType.SomeClass is installed as a COM+ component. I checked "type"
for null and it's not null.
Any help would be appreciated.



You need to install the library in the GAC by running gacutil /i <yourdll>

Willy.
 
Nicholas Paldino said:
Slavan,

Is SomeType.SomeClass a .NET component? If so, you need to have a
reference to the original assembly and create the type using the new
keyword. .NET components hosted in COM+ can not be created in .NET
through COM interop (which is essentially what you are trying to do, if
this is the case).

Hope this helps.

No, this is not true.
You can register a .NET component in the COM+ catalog and call it from
managed code as well as from native COM code.
What the OP it trying to do is create an instance of a .NET class using late
binding, no COM interop is involved here. When creating an instance from
native COM clients, then you effective create this instance through COM
interop.

Willy.


Willy.
 
No, this is not true.
You can register a .NET component in the COM+ catalog and call it from
managed code as well as from native COM code.
What the OP it trying to do is create an instance of a .NET class using late
binding, no COM interop is involved here. When creating an instance from
native COM clients, then you effective create this instance through COM
interop.

Willy.

Willy.

Could you provide code example on how to call COM+ component from .NET
client?
 
Slavan said:
Could you provide code example on how to call COM+ component from .NET
client?



It depends on how you would like to call the component, you can use early
binding as well as late binding.

Using late binding , you need to use reflection like this:
// say you have a method like....
public void SomeMethod(string message)
....

then your client can call it like this...
....
t = Type.GetTypeFromProgID("SomeType.SomeClass", true);
helper = Activator.CreateInstance(t);
// here I call "SomeMethod" passing a string as argument using
reflection.
helper.GetType().InvokeMember("SomeMethod", BindingFlags.Default
| BindingFlags.InvokeMethod, null, helper, new object[] {"Test" });
...

However, it's much better to call it using early binding,

1. Using a common interface assembly
// Interface - common assembly.
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
[Guid("....................................")]
public interface ISample
{
void SomeMethod(string message);
}

// Sample implementation class (another assembly)
// Class implementing ISample
public class Sample : ServicedComponent, ISample
{
public void SomeMethod(string xx)
{..}
}

Your client simply has to set a reference to the "common Interface"
assembly...
and call the method like this.

ISample sample;

// create instance..
Type t = Type.GetTypeFromProgID("SomeType.SomeClass", true);
object helper = Activator.CreateInstance(t);
sample = helper as ISample;
// Call method
sample.SomeMethod("test");

2. Using a reference to the server library.
Here you can just create an instance of the class using new.
Sample sample = new Sample();
sample.SomeMethod(...).


Willy.
 
Back
Top