none
Behaviour of multiple AppDomains with C++/CLI RRS feed

  • Question

  • I have a solution that starts out as a native executable which then loads a c++/cli library we will call MyProj.Interop which in turn loads a c# lib we will call MyProj.Manager which creates an AppDomain needed for sandboxing. This new AppDomain loads a new library we will call MyProj.Sandbox which loads MyProj.Interop and then creates a new instance of a callback interface (one was previously created in the old appdomain) which is then registered in the native executable. Now the managed callback manager is coded more or less like this:

     

     

    class CListener : public ICallback
    {
    private:
    	gcroot<IListener^> m_Listener;
    
    public:
    	CListener(IListener^ listener);
    	~CListener(void);
    
    	IListener^ GetListener();
    
    	virtual void OnCallback();
    };
    
    

    The problem is though, that I get the following error:
    An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
    
    Additional information: Cannot pass a GCHandle across AppDomains.
    

    Is there a way to get it to call the callback in the respective AppDomain CListener was created on?

     

    Edit: Saw http://lambert.geek.nz/2007/05/29/unmanaged-appdomain-callback/, which uses delegates but these are not the most friendly for large interfaces. Is there any other way?


    Tuesday, July 5, 2011 12:04 AM

All replies