Problem Invoking a .net dll (Class Library - com+)

S

shanmani

Hi,

I am developing a .NET application which will invoke the methods from
different COM / .NET DLLs. While invoking methods from .NET DLLs, I am
encountering the following error. I have also included the detail of the
error stack trace and the code that I have written to invoking the methods.

I would appreciate if you could let me know the cause of this error and
possible workarounds to avoid this situation.

Error Message
-------------

Cannot load type OrchServerSync.ASrvrSync, OrchServerSync, Version=3.0.6.0,
Culture=neutral, PublicKeyToken=5552a996b9dd0e5d.

Error StackTrace
----------------

at System.Runtime.Remoting.RemotingServices.GetOrCreateProxy(Identity idObj,
Object proxy, Boolean fRefine)\r\n at
System.Runtime.Remoting.RemotingServices.InternalUnmarshal(ObjRef objectRef,
Object proxy, Boolean fRefine)\r\n at
System.Runtime.Remoting.RemotingServices.Unmarshal(ObjRef objectRef)\r\n
at
System.EnterpriseServices.ServicedComponentProxyAttribute.CreateInstance(Type
serverType)\r\n at
System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(Type
serverType, Object[] props, Boolean bNewObj)\r\n at
System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)\r\n at
System.Activator.CreateInstance(Type type, Boolean nonPublic)\r\n at
System.Activator.CreateInstance(Type type)


Code used for Invoking:
----------------------

object retObj = null;

Type Obj = Type.GetTypeFromProgID(sClassName);

object ObjMsp = Activator.CreateInstance(Obj);

retObj = Obj.InvokeMember(sMethodName, BindingFlags.InvokeMethod, null,
ObjMsp, null);

System.Runtime.InteropServices.Marshal.ReleaseComObject(ObjMsp);

Thanks in advance
Dhandapani
 
W

Walter Wang [MSFT]

Hi Dhandapani,

Thank you for your post!

After reviewing the problem description, I am not clear on some points.
Could you please help me on the following questions so that we can work
more closely?
1) Is the COM component exposed from .NET?
2) Is the component a COM+ component deployed in remote COM+ explorer?
3) From your posted stack trace, it seems the exception is thrown from the
call to Activator.CreateInstance(), which means the Type info is retrieved
successfully. Maybe you could Add Watch on the Type instance to see whether
or not the assembly is located correctly.

If there is any something you would like to add, please feel free to reply
here. I am happy to work with you on this.

Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Walter Wang [MSFT]

Hi Praveen,

Based on my understanding, the question is:
1) You are building a ServicedComponent using Visual Studio 2003
2) You deployed it as a Server application in COM+ explorer
3) You are calling it using C# client with following code:

Type Obj = Type.GetTypeFromProgID(sClassName);
object ObjMsp = Activator.CreateInstance(Obj);

and get "Cannot load type" exception while calling "CreateInstance".

If I've misunderstood anything, please feel free to post here.

Based on my research, for Type.GetTypeFromProgID, if you don't provide
additional ServerName parameter, it's loading the type locally. Since a
COM+ server application runs in its own process, we must provide a
ServerName parameter to Type.GetTypeFromProgID to force it load the type
remotely with the Com Callable Wrapper (CCW). You can inspect the loaded
Type instance while debugging:

1) When not providing the ServerName parameter, the loaded assembly is the
locally installed one with the actual type
2) When providing the ServerName parameter, the loaded assembly is
mscorlib.dll, which is the actual COM implementation of all .NET exposed
components.

Actually, the recommended way to call a ServicedComponent built with .NET
from a .NET client is to reference the assembly and call with early-bind
rather than late-bind.

Hope this helps. Please feel free to post here if anything is unclear.




Regards,
Walter Wang
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top