Unable to instantiate managed plugin class

Good morning!

I’m creating a visual plugin on Visual Studio 2019 to Control on Delphi 10.2. But, I`m often getting this error, same as my main project.

Unable to instantiate managed plugin class. “PLuginHydra_Teste.UserControl1” Most likely the type is not declared as “public”, type or assembly are marked as ComVisible(false), or missing/incorrect license file is detected

Here the problem:

I created a Visual Hydra Plugin on Visual Studio 2019 and another project HydraUI_teste with a User Control that shows a bar.
Then I just compile the plugin and copy *.dll to Delphi project *.exe directory (Delphi 10.2).


In the projetct on Visual Studio (Hydra Plugin Project), if I put the instructions like this, it works good.

Visual Studio Project (Hydra Plugin)

        private void InitializeComponent()
        {
            components = new System.ComponentModel.Container();
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        }

In the other hand, if I instantiate the other project (Already imported in the plugin class). When i call it on Delphi, I get the error:

Visual Studio Project (Hydra Plugin)

        private void InitializeComponent()
        {
             components = new System.ComponentModel.Container();
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.fForm1 = new HydraUI_teste.FHydraUI(); /* Here */
        } 

Delphi Project:

   HYModuleManager.LoadModule(path+'PluginHydra_Teste.dll');
   HYModuleManager.CreateVisualPlugin('PluginHydra_Teste', fPluginHydra, pnlTeste); // Error Here

What I’ve checked:

  • Assembly Hydra Plugin is setted to ComVisible(true) (Both Projects);
  • The declared class is public on Visual Studio;
  • The class that is instantiated is declared as public too;
    public partial class FHydraUI : UserControl
    {
        public FHydraUI()
        {
            InitializeComponent();
        }
    }
  • The licence file seem fine (already excluded obj files and recompiled).

Thank you.

Follow a sample of both projects (Delphi 10.2) and (Visual Studio 2019)

Sample_2020-12-10.zip (1.2 MB)

Hello

There are significant issues with your testcase:

  1. You should NEVER add any custom code to auto-generated Designer files unless you want to break Visual Studio designer and/or lose your code
  2. Plugin cannot be defined as
    [Plugin(Name = "PluginHydra_Teste", Description = "Plugin Teste Hydra", UserData = "Data"), VisualPlugin]
    public partial class UserControl1 : RemObjects.Hydra.VisualPlugin

It should be inherited from VisualPlugin or NonVisualPlugin hydra classes:

    [Plugin(Name = "PluginHydra_Teste", Description = "Plugin Teste Hydra", UserData = "Data"), VisualPlugin]
    public partial class UserControl1 : RemObjects.Hydra.VisualPlugin
  1. If you plan to implement some plugin interface and then use that interface on the host side, then you have to properly define the plugin class by adding that interface to its declaration:
    [Plugin(Name = "PluginHydra_Teste", Description = "Plugin Teste Hydra", UserData = "Data"), VisualPlugin]
    public partial class UserControl1 : RemObjects.Hydra.VisualPlugin, IPluginHydra
  1. If you do not plan to display anything from the plugin and need just to call some plugin methods then you need to consider to use non-visual plugins instead of visual plugins.

Still after fixing steps 1-3 I was not able to reproduce the original issue. Plugin properly loads with and without the additional HydraUI_teste.FHydraUI class reference.
Please remember that if you reference some assemblies with custom classes, forms etc then you need to distribute these assemblies together with the plugin assembly itself.

Regards

Good Morning!

We’ve found the main problem,

  1. UI project should be a Class Library;
  2. Both generated *.dll must be in delphi *.exe directory project;

Thank you!