royalapplications / beyondnet

A toolset that makes it possible to call .NET code from other programming languages, including C and Swift.
https://royalapps.com
MIT License
108 stars 4 forks source link

`Assembly.SetEntryAssembly` bug #79

Open lemonmojo opened 1 month ago

lemonmojo commented 1 month ago

Remove workaround for Assembly.SetEntryAssembly bug in .NET 8.0.400 once a .NET release with a fix (or .NET 9) is out.

nil4 commented 1 month ago

SetEntryAssembly was added very recently in https://github.com/dotnet/runtime/pull/102271. That PR is under the 9.0.0 milestone.

But somehow, the implementation of that method actually made it into the recent 8.0.8 SDK release.

The System.Runtime.dll assembly type-forwards System.Reflection.Assembly to System.Private.CoreLib, where SetEntryAssembly is present -- see $DOTNET_ROOT/shared/Microsoft.NETCore.App/8.0.8/System.Runtime.dll. This means that beyondnetgen finds the method during its reflection scan.

However, the ref assembly at $DOTNET_ROOT/packs/Microsoft.NETCore.App.Ref/8.0.8/ref/net8.0/System.Runtime.dll does not include the method, since it's not part of the public API set for .NET 8.0.

Later when compiling the generated code, against the ref assemblies, the method is not found and the compiler rejects the code.

It seems that a ref/def mismatch made its way into .NET SDK 8.0.8. This should be resolved when we switch to a 9.0 SDK which should include the new method in its ref assemblies.

nil4 commented 1 month ago

Per https://github.com/dotnet/runtime/pull/103726 this was intentional:

The Azure functions team is using this API in .NET 9 and want to bring this APi back to .NET 8 in order to avoid adding too much unnecessary code for the scenario they are trying to support. This API will only be available via reflection.

lemonmojo commented 1 month ago

@nil4 Thx for the detailed explanation. 🙏 I guess this won't happen too often, so the temporary workaround is probably good enough.