AaronRobinsonMSFT / DNNE

Prototype native exports for a .NET Assembly.
MIT License
394 stars 41 forks source link

DNNE 2.01 .NET 6.x failure_load_runtime #164

Closed pf-amakarov closed 1 year ago

pf-amakarov commented 1 year ago

Hi,

I have a problem. With old version 1.0.34 and net5.0 I dont have this problem. Did I somehow forget to install a runtime or something?

image error_code -2147450715

The specified framework 'Microsoft.NETCore.App', version '6.0.0', apply_patches=1, version_compatibility_range=minor is incompatible with the previously loaded version '5.0.17'.Unhandled exception at 0x295A0175 (OPTO_XML_VD_Data_Selector_ParserNE.dll) in WinATS.exe: Fatal program exit requested.

installed runntimes: Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

5.0.416 [C:\Program Files\dotnet\sdk] 6.0.300 [C:\Program Files\dotnet\sdk] 6.0.402 [C:\Program Files\dotnet\sdk] 7.0.100 [C:\Program Files\dotnet\sdk] 7.0.200 [C:\Program Files\dotnet\sdk] 7.0.202 [C:\Program Files\dotnet\sdk]

DNNE *.JSON files: { "runtimeTarget": { "name": ".NETCoreApp,Version=v6.0/win-x86", "signature": "" }, "compilationOptions": {}, "targets": { ".NETCoreApp,Version=v6.0": {}, ".NETCoreApp,Version=v6.0/win-x86": { "OPTO_XML_VD_Data_Selector_Parser/1.0.0": { "dependencies": { "DNNE": "2.0.1" }, "runtime": { "OPTO_XML_VD_Data_Selector_Parser.dll": {} } }, "DNNE/2.0.1": {} } }, "libraries": { "OPTO_XML_VD_Data_Selector_Parser/1.0.0": { "type": "project", "serviceable": false, "sha512": "" }, "DNNE/2.0.1": { "type": "package", "serviceable": true, "sha512": "sha512-hVRxzk5rbssBBcUpawftrqegxu9fJbBhfGDjfnOhwKrjjzy4ZZooeTWrNM43joP1WgF8Q0+dYPdaRwL1IJIbwQ==", "path": "dnne/2.0.1", "hashPath": "dnne.2.0.1.nupkg.sha512" } } }

{ "runtimeOptions": { "tfm": "net6.0", "rollForward": "LatestMinor", "framework": { "name": "Microsoft.NETCore.App", "version": "6.0.0" }, "configProperties": { "System.Reflection.Metadata.MetadataUpdater.IsSupported": false } } }

AaronRobinsonMSFT commented 1 year ago

is incompatible with the previously loaded version '5.0.17'.

@AleksejMa What this is saying is there is already a version of .NET Core loaded in the current process (that is, 5.0.17). You are permitted to request to load "compatible" versions - which is difficult to define but generally as long as the major version is the same everything is satisfied. In this case, it looks like your new DNNE generated binary is looking to load .NET 6, but .NET 5.0.17 is already loaded and that means failure.

The version lookup algorithm for frameworks can be found here.

The fix here is either to target your DNNE to .NET 5 or move the loading application to .NET 6. Another option is to use the roll forward mechanism for your DNNE library.

pf-amakarov commented 1 year ago

@AaronRobinsonMSFT That means for my case, if .NET 5.x is not installed on the target system but only .NET 6.x, then it should work? That is, the problem occurs when multiple runtimes are installed. Because DNNE loads the minimal version on its own. I cannot externally influence which runtime is loaded (calling from ANSI C). Right?

AaronRobinsonMSFT commented 1 year ago

That means for my case, if .NET 5.x is not installed on the target system but only .NET 6.x, then it should work?

Only if the hosting application is targeting .NET 6 or that application has specified <RollForward>LatestMajor</RollForward> and it has decided to load .NET 6 even though it is targeting .NET 5.

That is, the problem occurs when multiple runtimes are installed. Because DNNE loads the minimal version on its own]

It loads the version defined by the TFM. For OPTO_XML_VD_Data_Selector_ParserNE.dll library seems to be targeting .NET 6. So an alternative would be to set that library's TargetFramework to net5.0. Once that is done, the library could also set <RollForward>LatestMajor</RollForward> and that would permit the system to target .NET 5, but be loadable by any process that .NET 5+.

I cannot externally influence which runtime is loaded (calling from ANSI C). Right?

There are ways to do this, but they would require editing the .runtimeconfig.json file for the library exporting the functions.

pf-amakarov commented 1 year ago

@AaronRobinsonMSFT I have understood it now. I now know which application loads the runtime. Thanks! 👍