From VB6 to .net via COM and Remoting...What a mess!
- by Robert
I have some legacy vb6 applications that need to talk to my .Net engine application.
The engine provides an interface that can be connected to via .net Remoting.
Now I have a stub class library that wraps all of the types that the interface exposes. The purpose of this stub is to translate my .net types into COM-friendly types. When I run this class library as a console application, it is able to connect to the engine, call various methods, and successfully return the wrapped types.
The next step in the chain is to allow my VB6 application to call this COM enabled stub.
This works fine for my main engine-entry type (IModelFetcher which is wrapped as COM_ModelFetcher). However, when I try and get any of the model fetcher's model types (IClientModel, wrapped as COM_IClientModel, IUserModel, wrapped as COM_IUserModel, e.t.c.), I get the following exception:
[Exception - type: System.InvalidCastException 'Return argument has an invalid type.'] in mscorlib
at System.Runtime.Remoting.Proxies.RealProxy.ValidateReturnArg(Object arg, Type paramType)
at System.Runtime.Remoting.Proxies.RealProxy.PropagateOutParameters(IMessage msg, Object[] outArgs, Object returnValue)
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at AWT.Common.AWTEngineInterface.IModelFetcher.get_ClientModel()
at AWT.Common.AWTEngineCOMInterface.COM_ModelFetcher.GetClientModel()
The first thing I did when I saw this was to handle the 'AppDomain.CurrentDomain.AssemblyResolve' event, and this allowed me to load the required assemblies. However, I'm still getting this exception now. My AssemblyResolve event handler is loading three assemblies correctly, and I can confirm that it does not get called prior to this exception.
Can someone help me untie myself from this mess of interprocess communication?!