Type resolution in secondary app domain

Here’s the weirdness in a nutshell (more details later).

I have a host-plugin situation. The plugin is created in its own app domain. It does not have access to host assemblies. The only thing in common between the plugin and the host are .NET framework assemblies, and a special assembly “Interfaces”, of which plugin and host hold two idential copies (important).

The plugin has a constructor accepting some interface.

class Plugin { public Plugin(IStuff stuff) {...} }

I use AppDomain.CreateInstanceAndUnwrap() with constructor arguments to instantiate the plugin.

The weirdness: If I pass a concrete implementation of IStuff whose type is accessible to Plugin, everything works fine. If concrete type is not accessible, I get “constructor not found” exception.

This does not apply to properties, if I declare a property of type IStuff, I can assign any IStuff implementation to it, regardless of accessibility (provided that it can marshalled to the remote app domain of course).

It looks like constructor search logic applies stricter rules than regular marshalling.

Leave a Reply

Your email address will not be published. Required fields are marked *