[4.0.77.1109] HostPanel.HostPlugin(..) gives a SerializationException

C# host and C# plugin scenario. Sample code:

public void StartLive(int _objID)
{
    IHYCrossPlatformNonVisualPlugin mgr = null;
    IHYCrossPlatformVisualPlugin dsp = null;
    Global.VendorManager.Load();
    string vendor = Global.VendorManager.GetVendorName[_objID];
    try
    {
        fCamID = _objID;
        try
        {
            moduleMgr.LoadModule(vendor+".dll", true);
        }
        catch { }
        mgr = moduleMgr.CreateInstance(moduleMgr.Plugins[vendor]) as IHYCrossPlatformNonVisualPlugin;
        mgr.Start();
        dsp = moduleMgr.CreateInstance(moduleMgr.Plugins[vendor+"Display"]) as IHYCrossPlatformVisualPlugin;
        hostPanel.HostPlugin(dsp as IBasePlugin); //<-- here I receive a SerializationException
        (dsp as IGenericDisplay).CamID = _objID;
        (dsp as IGenericDisplay).StartLive();
    }
    catch
    {
    }
}

Exception details below:
System.Runtime.Serialization.SerializationException was caught
HResult=-2146233076
Message=Type ‘System.Windows.Forms.Control+ControlCollection’ in assembly ‘System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089’ is not marked as serializable.
Source=System.Windows.Forms
StackTrace:
Server stack trace:
at System.Windows.Forms.Control.get_Controls()
at System.Windows.Forms.Control.set_ParentInternal(Control value)
at System.Windows.Forms.Control.set_Parent(Control value)
at RemObjects.Hydra.VisualPlugin.ShowParented(Control aParent)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at RemObjects.Hydra.IWinFormsVisualPlugin.ShowParented(Control aParent)
at RemObjects.Hydra.HostPanel.HostPlugin(IBasePlugin aPlugin)
at ApacsClient.Forms.TCameraForm.StartLive(Int32 _objID) in D:\Perforce\apacs\trunk\sources\ApacsVideo\src\ClientCS\Forms\TCameraForm.cs:line 400
InnerException:

Could you send a testcase where this issue reproduces to support@remobjects.com ?

This only started happening on my project partly converted from delphi to c#. In simple cases I did not notice this problem. Basically there are windowManager and vendorManager classes, which are controlled by a background thread, however all windows forms code is sent to the main thread with the Invoke(…) method.

I should also mention that the visualPlugin.ShowParented(…) method works fine (except for the control size/resize).

This problem does not occur when using simple cases (single thread, objects/forms created from the mainform). I have only noticed this when I’ve added a windowManager, which runs on a background thread, but all forms code is executed in the main thread with Form.Invoke(…).

Also a strange thing is that using visualPlugin.ShowParented(…) method works fine (except for size and resizing of visual plugin).

Seems it fails to send some object over the thread boundaries. Still could you create a small testcase? I am afraid that Hydra cannot properly handle such case, so reproducing the issue in controlled environment could help.

I think it’s a problem of loading plugins in a separate AppDomain.

Plugins are loaded into separate domains by default and there were none reports of such exception. I still need a testcase, because I cannot reproduce it locally (and thus cannot provide nor workaround neither fix)

It might be how you say it, however I just did a quick test by loading the plugin into the same AppDomain and HostPanel.HostPlugin(…) worked without any problems.

One thing that might help is that I use a UserControl to ceate a custom control with all other controls. This custom control then is hosted inside a hydra VisualPlugin. It might be that the UserControl is giving the exception, however if I put all controls directly on the VisualPlugin there are quite a lot of memory leaked after each closing of the plugin.

__________________________________________
| HydraVisualPlugin                      |
|________________________________________|
|                                        |
|    __________________________________  |
|    | CustomControl : UserControl    |  |
|    |________________________________|  |
|    |                                |  |
|    |                                |  |
|    |                                |  |
|    |                                |  |
|    |________________________________|  |
|________________________________________|