dotnet / runtimelab

This repo is for experimentation and exploring new ideas that may or may not make it into the main dotnet/runtime repo.
MIT License
1.42k stars 198 forks source link

MVC project doesn't work with NativeAOT #654

Closed FitchSun closed 3 years ago

FitchSun commented 3 years ago

I have built a new mvc project of netcore2.1, and the steps are following https://github.com/dotnet/corert/blob/master/samples/WebApi/README.md, but it throws exceptions when I try to access the url link, here's my log:

Hosting environment: Production Content root path: D:\WORK\mvcTest\bin\Debug\netcoreapp2.1\win-x64\publish Now listening on: http://localhost:5000 Now listening on: https://localhost:5001 Application started. Press Ctrl+C to shut down. fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1] An unhandled exception has occurred while executing the request. System.InvalidOperationException: No service for type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory' has been registered. at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider, Type) + 0x134 at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredServiceT + 0x88 at Microsoft.AspNetCore.Mvc.Controller.get_TempData() + 0xb0 at Microsoft.AspNetCore.Mvc.Controller.View(String, Object) + 0x8a at Microsoft.AspNetCore.Mvc.Controller.View(String) + 0x6c at Microsoft.AspNetCore.Mvc.Controller.View() + 0x2d at mvcTest.Controllers.HomeController.Index() + 0x30 at mvcTest!+0x176cbef at System.InvokeUtils.CalliIntrinsics.Call(IntPtr, IntPtr, Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x4b at System.InvokeUtils.CallDynamicInvokeMethod(Object, IntPtr, Object, IntPtr, IntPtr, Object, Object[], BinderBundle, Boolean, Boolean, Boolean) + 0x251 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception) + 0x2c at System.Linq.Expressions.Interpreter.ExceptionHelpers.UnwrapAndRethrow(TargetInvocationException) + 0x2c at System.Linq.Expressions.Interpreter.MethodInfoCallInstruction.Run(InterpretedFrame) + 0x259 at System.Linq.Expressions.Interpreter.Interpreter.Run(InterpretedFrame) + 0x6c at System.Linq.Expressions.Interpreter.LightLambda.Run(Object[]) + 0xac at mvcTest!+0x1e0236 at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object, Object[]) + 0x43 at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper, ObjectMethodExecutor, Object, Object[]) + 0x40 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d12.MoveNext() + 0x1e1 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d10.MoveNext() + 0x170 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext) + 0xa3 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ControllerActionInvoker.State&, ControllerActionInvoker.Scope&, Object&, Boolean&) + 0x98b
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d13.MoveNext() + 0xb3 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d18.MoveNext() + 0x151 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d16.MoveNext() + 0x2aa --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Builder.RouterMiddleware.d4.MoveNext() + 0x470 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.d7.MoveNext() + 0xa6f --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.d6.MoveNext() + 0x15f fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[3] An exception was thrown attempting to execute the error handler. System.InvalidOperationException: No service for type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory' has been registered. at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider, Type) + 0x134 at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredServiceT + 0x88 at Microsoft.AspNetCore.Mvc.Controller.get_TempData() + 0xb0 at Microsoft.AspNetCore.Mvc.Controller.View(String, Object) + 0x8a at Microsoft.AspNetCore.Mvc.Controller.View(Object) + 0x35 at mvcTest.Controllers.HomeController.Error() + 0x161 at mvcTest!+0x176cbef at System.InvokeUtils.CalliIntrinsics.Call(IntPtr, IntPtr, Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x4b at System.InvokeUtils.CallDynamicInvokeMethod(Object, IntPtr, Object, IntPtr, IntPtr, Object, Object[], BinderBundle, Boolean, Boolean, Boolean) + 0x251 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception) + 0x2c at System.Linq.Expressions.Interpreter.ExceptionHelpers.UnwrapAndRethrow(TargetInvocationException) + 0x2c at System.Linq.Expressions.Interpreter.MethodInfoCallInstruction.Run(InterpretedFrame) + 0x259 at System.Linq.Expressions.Interpreter.Interpreter.Run(InterpretedFrame) + 0x6c at System.Linq.Expressions.Interpreter.LightLambda.Run(Object[]) + 0xac at mvcTest!+0x1e0236 at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object, Object[]) + 0x43 at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper, ObjectMethodExecutor, Object, Object[]) + 0x40 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d12.MoveNext() + 0x1e1 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d10.MoveNext() + 0x170 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext) + 0xa3 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ControllerActionInvoker.State&, ControllerActionInvoker.Scope&, Object&, Boolean&) + 0x98b
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d13.MoveNext() + 0xb3 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d18.MoveNext() + 0x151 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d16.MoveNext() + 0x2aa --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Builder.RouterMiddleware.d4.MoveNext() + 0x470 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.d7.MoveNext() + 0xa6f --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.d6.MoveNext() + 0x705 fail: Microsoft.AspNetCore.Server.Kestrel[13] Connection id "0HM6BP8BKCO81", Request id "0HM6BP8BKCO81:00000001": An unhandled exception was thrown by the application. System.InvalidOperationException: No service for type 'Microsoft.AspNetCore.Mvc.ViewFeatures.ITempDataDictionaryFactory' has been registered. at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider, Type) + 0x134 at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredServiceT + 0x88 at Microsoft.AspNetCore.Mvc.Controller.get_TempData() + 0xb0 at Microsoft.AspNetCore.Mvc.Controller.View(String, Object) + 0x8a at Microsoft.AspNetCore.Mvc.Controller.View(String) + 0x6c at Microsoft.AspNetCore.Mvc.Controller.View() + 0x2d at mvcTest.Controllers.HomeController.Index() + 0x30 at mvcTest!+0x176cbef at System.InvokeUtils.CalliIntrinsics.Call(IntPtr, IntPtr, Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x4b at System.InvokeUtils.CallDynamicInvokeMethod(Object, IntPtr, Object, IntPtr, IntPtr, Object, Object[], BinderBundle, Boolean, Boolean, Boolean) + 0x251 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception) + 0x2c at System.Linq.Expressions.Interpreter.ExceptionHelpers.UnwrapAndRethrow(TargetInvocationException) + 0x2c at System.Linq.Expressions.Interpreter.MethodInfoCallInstruction.Run(InterpretedFrame) + 0x259 at System.Linq.Expressions.Interpreter.Interpreter.Run(InterpretedFrame) + 0x6c at System.Linq.Expressions.Interpreter.LightLambda.Run(Object[]) + 0xac at mvcTest!+0x1e0236 at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object, Object[]) + 0x43 at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper, ObjectMethodExecutor, Object, Object[]) + 0x40 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d12.MoveNext() + 0x1e1 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d10.MoveNext() + 0x170 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext) + 0xa3 at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ControllerActionInvoker.State&, ControllerActionInvoker.Scope&, Object&, Boolean&) + 0x98b
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d13.MoveNext() + 0xb3 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d18.MoveNext() + 0x151 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d16.MoveNext() + 0x2aa --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Builder.RouterMiddleware.d4.MoveNext() + 0x470 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.d7.MoveNext() + 0xa6f --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.d6.MoveNext() + 0x15f --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.d6.MoveNext() + 0x838 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x32 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0xe4 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x86 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x2e at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0x1a at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.d188`1.MoveNext() + 0x4e4

Then I tried to work this out with a netcore3.1 project but I failed again(the result was different but i lost it, sry), is there sth wrong with my operation? Besides, I'd like to know that will nativeAOT run properly with a netcore3.1 mvc project so far, for my final purpose is to generate native code for my netcore3.1 project, thx!

kant2002 commented 3 years ago

@FitchSun did you check with .NET 5.0 ? Default application works out of the box a you can see in the sample https://github.com/dotnet/runtimelab/pull/666

MichalStrehovsky commented 3 years ago

Thank you for testing this out with the latest @kant2002.

I think the problem @FitchSun is hitting is specific to using the 1.0.0-alpha-* NuGet packages that the archived CoreRT repo refers to. Those packages are no longer updated. The System.InvokeUtils.CalliIntrinsics.Call in the stack trace no longer exists in the 6.0 packages. Following @kant2002 sample should unblock this.