Can't get RazorPageOptions from DI with version 6.0.3 of Mvc.Razor.RuntimeCompilation
See original GitHub issueIs there an existing issue for this?
- I have searched the existing issues
Describe the bug
Getting RazorPageOptions
from dependency injection with AddRazorRuntimeCompilation()
called on ServiceCollection
throws an exception preventing the application to start because the Conventions
property is null. When using MapControllerRoute()
for example.
This issue came up with the version 6.0.3 of Mvc.Razor.RuntimeCompilation. This commit could be responsible for this bug.
Expected Behavior
The service provider should build a RazorPageOptions
as expected when using razor runtime compilation.
Steps To Reproduce
If using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
in version 6.0.3 (6.0.2 works as expected)
public void ConfigureServices(IServiceCollection services)
{
services
.AddControllersWithViews()
.AddRazorRuntimeCompilation();
}
public void Configure(IApplicationBuilder app)
{
app.UseEndpoints(endpoints => endpoints.MapControllerRoute("default", "{controller}/{action}/{id?}")); // Throws ArgumentNullException
}
Exceptions (if any)
Value cannot be null. (Parameter ‘source’)
at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
at System.Linq.Enumerable.OfType[TResult](IEnumerable source)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageActionDescriptorProvider..ctor(IEnumerable``1 pageRouteModelProviders, IOptions``1 mvcOptionsAccessor, IOptions``1 pagesOptionsAccessor)
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span``1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
...
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.GetOrCreateDataSource(IEndpointRouteBuilder endpoints)
at Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllerRoute(IEndpointRouteBuilder endpoints, String name, String pattern, Object defaults, Object constraints, Object dataTokens)`
.NET Version
6.0.200
Anything else?
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Adding AddRazorRuntimeCompilation() to the container in ...
Now I add the NuGet dependency Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation version 6.0.0. In Program.cs file, I add a line // Add services ...
Read more >Razor file compilation in ASP.NET Core
Learn how compilation of Razor files occurs in an ASP. ... Runtime compilation may be optionally enabled by configuring the project.
Read more >Enable Razor Runtime Compilation
This article/tutorial will show you how to enable runtime compilation when creating ASP.NET Core and ASP.NET Core MVC projects.
Read more >Enabling Razor Runtime Compilation after creating your ASP ...
aspnetcore #dotnet #dotnetcore All about Razor Runtime Compilation in .NET Core MVC - I recently came across an interesting issue where ...
Read more >Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation 6.0.6
Runtime compilation support for Razor views and Razor Pages in ASP.NET Core MVC. This package was built from the source code at...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The 6.0.201 SDK seems to fix the issue.
I confirm that updating the SDK from 6.0.200 to 6.0.201 fixed the issue. I guest we will also have to update the ASP.NET Core Runtime to v6.0.3 on the servers.