dotnet / dotnet/aspnetcore

ArgumentNullException when requesting a Razor Page

Open
#56,879 2 comments 3 reactions 0 assignees View on GitHub
area-mvc untriaged
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

Hi, we have a hard-to-reproduce issue and are struggling to find a solution. We serve pages using a custom implementation of the `IFileProvider` and `IFileInfo`. On rare occasions, a page request will get a 500 response, and we can find this Exception/StackTrace in our logs:

```
System.ArgumentNullException: Value cannot be null. (Parameter 'type')
at System.ArgumentNullException.Throw(String paramName)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.CompiledPageActionDescriptorFactory.CreateCompiledDescriptor(PageActionDescriptor actionDescriptor, CompiledViewDescriptor viewDescriptor)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.DefaultPageLoader.LoadAsyncCore(PageActionDescriptor actionDescriptor, EndpointMetadataCollection endpointMetadata)
at Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure.PageLoaderMatcherPolicy.ApplyAsyncAwaited(PageLoader pageLoader, CandidateSet candidates, Task`1 actionDescriptorTask, Int32 index)
at Microsoft.AspNetCore.Routing.Matching.DfaMatcher.SelectEndpointWithPoliciesAsync(HttpContext httpContext, IEndpointSelectorPolicy[] policies, CandidateSet candidateSet)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.g__AwaitMatch|10_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask)
```

Once a page gets this error, every user requesting the same page will get this error. At the moment, we can only resolve this by restarting the server. Nothing seems to be wrong with the Razor page, as a server restart always resolves the issue.

Is there anything about how we provide a page to the file provider that can result in this exception?

Contributor guide

Open the contributing guide

Research direction

Start with the stack trace at CompiledPageActionDescriptorFactory.CreateCompiledDescriptor and DefaultPageLoader.LoadAsyncCore, then inspect how the custom IFileProvider and IFileInfo supply Razor pages. No reproduction or test is named; done would be a reliable reproduction or confirmed explanation of the null type, with coverage for the failing request path.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.