Skip to content

NativeAOT with reflection disabled working in .NET 7, not in .NET 8 for new KestrelServer #50255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
LLT21 opened this issue Aug 22, 2023 · 7 comments
Closed
1 task done
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions NativeAOT

Comments

@LLT21
Copy link

LLT21 commented Aug 22, 2023

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

2 years ago I spent quite some time (and David Fowler even corrected my code in https://github.com/LLT21/NativeAOT5) to make a tiny kestrel that worked with Native AOT and reflection disabled for reasons described in closed issue #31561.

I upgraded the tiny kestrel code today to make it in sync with the one I use in the TechEmpower benchmarks under framework https://github.com/LLT21/FrameworkBenchmarks/tree/master/frameworks/CSharp/appmpower:

  1. First I upgraded to .NET 7: this is the project that now is in the master of https://github.com/LLT21/NativeAOT5. If one compiles this native with reflection disabled - specified in project file - on Mac M1 or Linux, this works perfect and runs as such each week successfully in the TechEmpower benchmarks.
  2. Then I upgraded to .NET 8 and receive an Unhandled Exception: MT4302744992: Reflection_Disabled error on the line: using var kestrelServer = new KestrelServer(Options.Create(kestrelServerOptions), socketTransportFactory, NullLoggerFactory.Instance); -> some reflection code has been added here in .NET 8.

The output is:

Unhandled Exception: MT4302744992: Reflection_Disabled
   at Internal.Reflection.RuntimeTypeInfo.get_Name() + 0x5d
   at Microsoft.Extensions.Internal.TypeNameHelper.ProcessType(StringBuilder&, Type, TypeNameHelper.DisplayNameOptions&) + 0x9c
   at Microsoft.Extensions.Internal.TypeNameHelper.GetTypeDisplayName(Type, Boolean, Boolean, Boolean, Char) + 0x36
   at Microsoft.Extensions.Logging.Logger`1..ctor(ILoggerFactory) + 0x23
   at Microsoft.Extensions.Logging.LoggerFactoryExtensions.CreateLogger[T](ILoggerFactory) + 0x2f
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServer..ctor(IOptions`1, IConnectionListenerFactory, ILoggerFactory) + 0x76
   at tinykestrel.Program.<Main>d__0.MoveNext() + 0x119
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x1c
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0x6a
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task, ConfigureAwaitOptions) + 0x53
   at tinykestrel.Program.<Main>(String[]) + 0x26
   at tinykestrel!<BaseAddress>+0x3424d0

Could you please have a look into this as it is crucial for us to keep this tiny bit working.
@davidfowl : do you have an idea for the cause of this ?

Expected Behavior

Would be nice to keep the behavior backward compatible

Steps To Reproduce

Compile https://github.com/LLT21/NativeAOT5 with .NET 7 and with .NET 8: with the former it is working, with the latter not.

Exceptions (if any)

No response

.NET Version

8.0.100-preview.7.23376.3

Anything else?

No response

@LLT21
Copy link
Author

LLT21 commented Aug 22, 2023

My first idea about this is that this commit: 0c42c03 has introduced SimpleHttpsConfigurationService also in case of no https, which causes the above. If it would be possible to make this dependent on http/https then the issue could be resolved.

@LLT21
Copy link
Author

LLT21 commented Aug 22, 2023

Just tested with .NET 8 preview 3: reflection disabled works; .NET 8 preview 4: reflection disabled does not work

@Tratcher
Copy link
Member

@amcasey, @halter73

@halter73
Copy link
Member

Does SimpleHttpsConfigurationService even need to have a real implementation of PopulateMultiplexedTransportFeatures? KestrelServer always passes in Array.Empty<IMultiplexedConnectionListenerFactory>() to the KestrelServerImpl.

@halter73
Copy link
Member

I opened #50272 against release/8.0 to remove the implementation of SimpleHttpsConfigurationService.PopulateMultiplexedTransportFeatures.

@adityamandaleeka
Copy link
Member

@halter73 This can be closed now right? I think it didn't get auto-associated with the PR because the PR isn't against main.

@LLT21
Copy link
Author

LLT21 commented Aug 23, 2023

I can fully support the closing of this issue. Never seen such a quick resolution at this level and stage. Thanks.

@LLT21 LLT21 closed this as completed Aug 23, 2023
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions NativeAOT
Projects
None yet
Development

No branches or pull requests

5 participants