Friday, April 29, 2011

.Net COM DLL not working from vb6 across appdomains

We have a large vb6 application, and as we need to change/fix things, we are moving sections to .net, targeting the framework 2.0. We have moved a bunch of classes to a .net dll, and they are set up properly to be exposed to com.

Here's the problem: MainAppVB6.exe instantiates DOTNET_COM.ComClass. It passes this to a method in a differen .net dll, which passes it across an appdomain. This is no issue at all for COM objects written in vb6.

.net see the appdomain boundary, and wants the objects to be serializable or marshalbyref. Since we need the .net portion to change data that gets back to vb6, serializable doesn't work. If we mark the classes at Inherits MarshalByRefObject, then we get "This remoting proxy has no channel sink which means either the server has no registered server channels are listening, or the application has no suitable client channel to talk to the server".

There are no channels -- we are just going across an appdomain in the same dll. It seems that .net is not treating the object as COM, which it should be doing.

If I remove both marshalbyref and serializable, things work only if the com object is instantiated by vb6. If the .net functionality in the appdomain creates the object and assigns to to be passed back to vb6, vb6 gives me automation errors.

A very ugly kludge is to serialize the object in the new appdomain, send back the xml, and let vb6 deserialize, but that seems ridiculous.

Anyone have any ideas?

Thank you.

Seth

From stackoverflow
  • You could create a delegate to the appropriate mutator method on your COM class in your first .NET method, pass that delegate across the AppDomain boundary, use that delegate to mutate your COM object in the second .NET method and then return the mutated object back to VB6. The methods in the Marshal Class might come in handy. :)

    Edit from comment: What about creating a .net copy of the vb6 class in the first .net call, passing that new object around to all the .net calls you need to make and then fix your com object going back. That might be easier than the de-serialization in vb6.

0 comments:

Post a Comment