FoxPro and .NET Interop
Error with DotNetCoreBridge
Gravatar is a globally recognized avatar based on your email address. Error with DotNetCoreBridge
  Guillaume Engelen
  All
  Dec 14, 2020 @ 06:19am

Hi Rick,

In the past I used the wwDotNetBridge a couple of times, thanks again for that it has been a lifesaver, and I was looking to change some of my dll's to .Net Core. When I run the dotnetcode.prg, in the examples directory, I get the error regarding the loading of the CLR instance on CREATEOBJECT("wwDotnetCoreBridge") (using the Framework version, wwDotnetBridge, works fine).

When I step into the code the line : lcRuntimePath = this.GetDotnetCoreRuntimeFolder(this.cRuntimeFolder) returns "C:\Program Files (x86)\dotnet\shared\Microsoft.NETCore.App\5.0.1" and the line : lnDispHandle = CoreClrCreateInstanceFrom(lcRuntimePath,lcVersion,@lcError,@lnSize) has lcVersion = "7.9.0.0" but returns a handle of 0.

Any idea whats going wrong?

Thanks in advance for any suggestions,

Guillaume

Gravatar is a globally recognized avatar based on your email address. re: Error with DotNetCoreBridge
  Rick Strahl
  Guillaume Engelen
  Dec 14, 2020 @ 01:44pm

Not sure. I need to look at it again with .NET Core 5. This Core support is experimental at this point...

If you're building .NET components for use with FoxPro you'll be better off using full framework rather than Core. It'll be more reliable and built-in - otherwise you'll have runtime dependencies that might not be there (ie. .NET Core 5.0 not installed).

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Error with DotNetCoreBridge
  Guillaume Engelen
  Rick Strahl
  Dec 15, 2020 @ 12:41am

Hi Rick,

Thanks for the quick reply.

Would like to use the framework version but I have to call a dll which is only available in Core version. I have earlier version of Core runtimes, 3.0 and 3.1, installed on the machine but it seems that the code always looks for the latest installed version.

For the moment I will try to develop a work-around.

Thanks again,

Guillaume

Gravatar is a globally recognized avatar based on your email address. re: Error with DotNetCoreBridge
  Rick Strahl
  Guillaume Engelen
  Dec 16, 2020 @ 11:39am

3.x assemblies will work under .NET Core 5.0 it's backwards compatible. But not the other way around (for obvious reasons).

Honestly I haven't looked at that code since 5.0 released so not sure whether anything has changed in the requirements etc. I have to take a look.

You can explicitly specify the runtime by providing the runtime folder in the object creation.

************************************************************************
* wwDotnetBridge ::  Init
****************************************
***  Function: Initializes the .NET runtime inside of FoxPro
***    Assume: Calls Load() to actual perform load operation
***      Pass: lcRuntimeFolder -  specific .NET Version or
***                         Full Runtime Path: <full path>
***                         Version only; 2.2.5, 2.1.4, 3.0.1
***                         Partial Version: 2.2 2.1 3.0
***            llUseCom  -  if .T. loads .NET Bridge via
***                         plain COM interop rather than 
***                         hosting .NET runtime itself.
***                         If you do COM 
***    Return: nothing
************************************************************************
FUNCTION Init(lcRuntimeFolder)

Maybe try with 3.1 runtime folder and see if that works in case something has changed.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Error with DotNetCoreBridge
  Guillaume Engelen
  Rick Strahl
  Dec 16, 2020 @ 11:33pm

Hi Rick,

Passing the path to the 3.1 runtimes solved the problem.

Thanks for the help.

Guillaume

Gravatar is a globally recognized avatar based on your email address. re: Error with DotNetCoreBridge
  Rick Strahl
  Guillaume Engelen
  Dec 17, 2020 @ 12:22pm

Thank for letting me know. I'll take a look at this to see why the Core 5.x runtime won't work. I suspect because it's not finding the runtime correctly perhaps.

This is one of the reasons why I'm so hesitant to recommend using any .NET Core interfaces if it can be avoided. Getting the versions matched up is going to be a PITA. Your app will be responsible for determining whether the right runtime(s) are installed which sucks (it's like the bad old days of .NET Framework). It's one thing for a full application, but crappy for a support component.

+++ Rick ---

© 1996-2024