"Exception has been thrown by the target of an invocation." occurring when calling CreateVisualPlugin()

I have a basic Plugin app built with C# and I have a Host app in D2010.

The Plugin has a Map Control from “Great Maps for Windows” (http://greatmaps.codeplex.com/releases/view/20235).

My Delphi code is below. It loads the plugin module fine, but it throws the exception when it tries to do CreateVisualPlugin().

If I remove the Great Maps component and put other components (e.g. Buttons, checkboxes, etc.), it loads and displays the plugin just fine.

The strange thing is that this has worked for a couple of years with this particular Map Control and I have not updated it at all.

When I updated to Hydra v4.0.71.1093.exe recently, however, it no longer works.

Please help.

Thanks,

Shane

unit fMain;

interface

uses
Windows,
Messages,
SysUtils,
Variants,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
uHYModuleManager,
uHYIntf,
StdCtrls,
ExtCtrls;

type
TMainForm = class(TForm)
HYMM: THYModuleManager;
pnlTop: TPanel;
pnlMap: TPanel;
btnLoad: TButton;
procedure btnLoadClick(Sender: TObject);
private
FMapVisualPlugin: IHYVisualPlugin;
public
{ Public declarations }
end;

var
MainForm: TMainForm;

const
MapModuleName = ‘TestPlugin.dll’;
MapPluginName = ‘TestPlugin.ThePlugin’;

implementation

{$R *.dfm}

procedure TMainForm.btnLoadClick(Sender: TObject);
begin
HYMM.LoadModule(MapModuleName);
HYMM.CreateVisualPlugin(MapPluginName, FMapVisualPlugin, pnlMap);
end;

Can you please launch this application from Visual Studio. TargetInvocationException is thrown by the .NET when other exception is occured in method that is called via reflections, it wraps original exception so it is hard to tell what the real problem is.

Here is what you can do:

  1. Go to your plugin project options and open “Debug” tab
  2. Change “Start Action” to “Start Application” and set path to your host exe file
  3. In “Debug” menu select “Exceptions” option and in the appeared dialog check “Common Language Runtime Exceptions”
  4. Start your plugin

Now from your host application click button to load a plugin and you should get a real exception.

Well I experienced this error every time when I forgot to include a hydra license in wpf project. Make sure you don’t forget to do so. Otherwise I would recommend to go deeper and try to catch an event coming from unmanaged code. VS project properties -> debug -> start external program (include your host app in delphi).
Then in debug menu in VS go for Debug -> Exceptions and select Win32 exc, CLR ex, what ever u might think that is causing an issue.