Casting .Net plugin to custom interface in .Net Host

Attempting to create testing environment entirely in .Net project

I have a simple PlugIn implemented using a custom interface

public class Plugin1 : VisualPlugin, IPlugIn1

IPlugIn1 is a .net interface implementing IHYCrossPlatformInterface

There is only a string property defined in IPlugIn1

public interface IPlugIn1 : IHYCrossPlatformInterface
    string Message { get; set; }


When I try to get to the Message property in the .net host, I cannot cast the plugin to IPlugIn1. So I have no way of setting the property.

        Instance = moduleManager.CreateInstance("My.PlugIns.Plugin1");
        (Instance as IPlugIn).Message = "Test";

The last line, above, fails.


.NET host - .NET plugin combination don’t use COM to perform calls to the plugin. Instead native .NET method calls are performed.

As far as I understnd you have redefined the IPlugIn1 interface once again in the host application? For the .NET type system this redefined IPlugIn1 is a completely different type than the IPlugIn1 interface defined in the plugin.

So to get this working you need the following:

  1. Move the IPlugIn1 definition to a separate assembly.
  2. Reference this assembly from both plugin and host

This will allow you to cast the plugin instance to the desired interface type.


Worked like a charm. Thank you!

1 Like