Hydra 4 -> Hydra 5 Upgrade Issues

I have .NET plugin modules used with a Delphi XE3 project which work with Hydra 4. I am evaluating Hydra 5 and am getting the following exception:

Unable to cast COM object of type ‘System.__ComObject’ to interface type ‘RemObjects.Hydra.CrossPlatform.IHYCrossPlatformHost’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{C518DE62-CEDF-47E7-8267-669885AE0949}’ failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)) Process WFV.exe (3936)

Some background – I originally built the .NET plugin module using Visual Studio 2010 and Hydra 4, targeting .NET Framework 4. I just installed Visual Studio 2017 and Hyrda 5 and rebuilt the project. I also installed Hydra 5 on my Delphi XE3 VM, replaced RemObjects.Hydra.dll with version 5, and replaced my .NET 4 assembly built with VS 2017.

Here’s how I’m loading the plugin:

var
  fNonVisualPlugin: IHYNonVisualPlugin;

procedure TMyThread.Execute;
var
  ModuleManager: THYModuleManager;
begin
  ModuleManager := THYModuleManager.Create(nil);
  try
    ModuleManager.ResolveInterfacesToOwner := True;
    ModuleManager.LoadModule(ExtractFilePath(Application.ExeName)+DLL_PATH);
    ModuleManager.CreateNonVisualPlugin('MyPlugin', fNonVisualPlugin); // exception here
  except on e: Exception do
    begin
      outputdebugstring(pchar('exception: '+e.Message));
    end;
  end;
end;

UPDATE: It seems if I load the module and plugin from with the context of a form or frame, where I drop a THYModuleManager icon in the designer view in Delphi, the plugin loads fine. However, when I try THYModuleManager.Create(nil) from the context of a thread, CreateNonVisualPlugin fails with the exception. Is this relevant somehow? Does the Hydra 5 trial popup window potentially cause issues?

Hydra 5 trial popup window potentially can cause issues because trial popup window are shown from background thread.

can you create a simple testcase that reproduces this case, pls?
we will test it

Attached are two projects, one from Visual Studio 2017 (the plugin) and one from Delphi XE3 (the host). When I run the Delphi program and click the test Hydra button on the UI the first time, it works fine. The second time I click the button, I get the exception in my previous post. Would you please take a look?

My Delphi XE3 program (not the attached test project) produces that COM object error each time from a background thread, albeit with a different plugin.

wsmod - Visual Studio 2017.zip (45.8 KB)
TestHydra5 - Delphi.zip (1.0 MB)

I can’t reproduce problem with your binaries from TestHydra5 - Delphi.zip.
it works as expected:

Animation

Just for clarification, are you running the project within Delphi and not seeing an exception logged from the line with outputdebugstring? I don’t log the exception in Form2 in the binaries, so it will still say Complete even if the exception is thrown. Attached is a second project that prints the exception to Form2 instead of saying Complete.

Here’s what I see the second time I click the button:

08 AM

TestHydra5 - VS 2017 2.zip (1.1 MB)

I can reproduce this:

08 AM

earlier, I just launched your precompiled binaries w/o IDE.

Thanks, can you please look into it and let me know what you find?

Hello

Seems this is related to plugin accessing Windows UI from a non-main thread (ie showing that MessageBox). You can see the same error if you’ll take Hydra 4 plugin and add a MessageBox.Show call to the plugin’s constructor. Seems this somehow damages the .NET COM interop.

We’ll investigate this deeper, yet atm I am not sure that we’ll be able to somehow override this.

Regards

Thanks for looking into this. I’ve been running production code with Hydra 4 using the same strategy for almost two years now–show a modal TForm and run a Hydra 4 NonVisualPlugin in a background TThread to load something in .NET. When I upgraded from Visual Studio 2010/Hydra 4 to Visual Studio 2017/Hydra 5 and recompiled the production NonVisualPlugin with the trial, I get this COM error message every time in my production software. Don’t know if this helps or not.

My goal in upgrading to Hydra 5 is to be able to use the Windows.Services.Store API in a Desktop Bridge app. But, I’d like to use the latest Visual Studio (2017) for doing the UWP development part in .NET. Does Hydra 4 support Visual Studio 2017, even if it doesn’t integrate with the File -> New -> Project dialog?

Hello

This is what causes the error. The trial means a message box when the plugin is instantiated. And a message box means broken COM when called from a non-UI thread.

Yes, you should be able to build Hy4 projects in VS 2017. Ofc there will be no IDE integration and/or project and item templates available.

Regards

My apologies, I didn’t fully digest your previous message. I understand now that I will get this error as long as I use the trial because of the message popup. This is unfortunate, since I can’t fully test Hydra 5 before purchase. Thank you for your support on this.

Well, seems we have found a workaround that makes your testcase work even with Trial nag screen.

You need to just add AcriveX to uses clause of the Unit2 module, and then add

CoInitialize(nil);

call as the first code line of the TWsmodThread.Execute method and the

CoUninitialize;

call as the last line in the finally clause, after the FreeAndNil(ModuleManager); call

Hope that helps

We just went ahead and purchased a license extension for Hydra 5 and verified that the issue no longer exists since the trial nag screen is not displayed. Unfortunately, I didn’t get to test your solution with the trial, but I suppose future devs can find a solution here with the trial. (I remember having an older ActiveX component a few years ago that I had to use CoInitialize after closing it out, perhaps should have thought of that).

Thanks again for your support here. We’re very happy with Hydra since it gives our Delphi app a bridge to the .NET world. Great technology.

1 Like