Skip to content
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

Make Source Generator for UseMiddleware #45528

Open
eerhardt opened this issue Dec 9, 2022 · 5 comments
Open

Make Source Generator for UseMiddleware #45528

eerhardt opened this issue Dec 9, 2022 · 5 comments
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware
Milestone

Comments

@eerhardt
Copy link
Member

eerhardt commented Dec 9, 2022

When I dotnet publish -c Release -p:PublishAot=true the following app:

var app = new ApplicationBuilder(serviceProvider: null);

UseMiddlewareExtensions.UseMiddleware<HiMiddleware>(app);

public class HiMiddleware
{
    public Task Invoke(HttpContext context)
    {
        Console.WriteLine("hi");
        return Task.CompletedTask;
    }
}

We should create a Source Generator for UseMiddleware so we don't need to use Reflection on NativeAOT. See #45890

Original issue (outdated)

I get the following AOT warnings stemming from the UseMiddleware method:

/_/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/ArrayOperations.cs(23): AOT analysis warning IL3050: System.Linq.Expressions.Interpreter.NewArrayInitInstruction.Run(InterpretedFrame): Using member 'System.Array.CreateInstance(Type,Int32)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The code for an array of the specified type might not be available. [C:\DotNetTest\AspNetTest\AspNetTest.csproj]
/_/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/ArrayOperations.cs(52): AOT analysis warning IL3050: System.Linq.Expressions.Interpreter.NewArrayInstruction.Run(InterpretedFrame): Using member 'System.Array.CreateInstance(Type,Int32)' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The code for an array of the specified type might not be available. [C:\DotNetTest\AspNetTest\AspNetTest.csproj]
/_/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/Interpreter/ArrayOperations.cs(87): AOT analysis warning IL3050: System.Linq.Expressions.Interpreter.NewArrayBoundsInstruction.Run(InterpretedFrame): Using member 'System.Array.CreateInstance(Type,Int32[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The code for an array of the specified type might not be available. [C:\DotNetTest\AspNetTest\AspNetTest.csproj]
/_/src/libraries/System.Linq.Expressions/src/System/Dynamic/Utils/TypeUtils.cs(28): AOT analysis warning IL3050: System.Dynamic.Utils.TypeUtils.GetNullableType(Type): Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. [C:\DotNetTest\AspNetTest\AspNetTest.csproj]
/_/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/MethodCallExpression.cs(1379): AOT analysis warning IL3050: System.Linq.Expressions.Expression.ApplyTypeArgs(MethodInfo,Type[]): Using member 'System.Reflection.MethodInfo.MakeGenericMethod(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. [C:\DotNetTest\AspNetTest\AspNetTest.csproj]
/_/src/libraries/System.Linq.Expressions/src/System/Linq/Expressions/BinaryExpression.cs(2239): AOT analysis warning IL3050: System.Linq.Expressions.Expression.GetResultTypeOfShift(Type,Type): Using member 'System.Type.MakeGenericType(Type[])' which has 'RequiresDynamicCodeAttribute' can break functionality when AOT compiling. The native code for this instantiation might not be available at runtime. [C:\DotNetTest\AspNetTest\AspNetTest.csproj]

This causes AOT warnings for ASP.NET apps that want to use EndPoints and Routing because we call UseMiddleware to enable these features:

return builder.UseMiddleware<EndpointRoutingMiddleware>(endpointRouteBuilder);

return builder.UseMiddleware<EndpointMiddleware>();

At a minimum, we should remove the AOT warnings from the above 2 callsites, so we can publish an ASP.NET Web API application for NativeAOT with no warnings.

As a follow up after that, we should consider a mechanism for solving this warning generally, for example with a source generator that generates the necessary code at compile-time.

@javiercn javiercn added the area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Dec 12, 2022
@captainsafia captainsafia added this to the .NET 8 Planning milestone Dec 13, 2022
@ghost
Copy link

ghost commented Dec 13, 2022

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@JamesNK
Copy link
Member

JamesNK commented Jan 5, 2023

@eerhardt How come these warnings are coming from System.Linq.Expressions files? Has that project not been annotated for AOT yet?

@eerhardt
Copy link
Member Author

eerhardt commented Jan 5, 2023

Has that project not been annotated for AOT yet?

No, it hasn't. There are a lot of libraries in dotnet/runtime that haven't been annotated for AOT. See dotnet/runtime#75480.

@eerhardt eerhardt changed the title Eliminate AOT Warnings related to UseMiddleware Make Source Generator for UseMiddleware Jan 12, 2023
@eerhardt eerhardt removed this from the 8.0-preview1 milestone Jan 12, 2023
@captainsafia captainsafia added this to the .NET 8 Planning milestone Jan 12, 2023
@ghost
Copy link

ghost commented Jan 12, 2023

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@captainsafia
Copy link
Member

Triage: Parking this back in .NET 8 Planning to avoid it surfacing in the triage query.

@captainsafia captainsafia added area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware and removed area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels labels Jun 20, 2023
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 6, 2024
@wtgodbe wtgodbe removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
@dotnet dotnet deleted a comment from dotnet-policy-service bot Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-middleware Includes: URL rewrite, redirect, response cache/compression, session, and other general middlesware
Projects
No open projects
Status: No status
Development

No branches or pull requests

7 participants