aspnetcore: NullReferenceException in IISHttpContext
Describe the bug
Since updating a website running in Azure App Service to use ASP.NET Core 2.2.0 with in-process hosting, I’ve observed a small number of NullReferenceException
s being thrown via Application Insights.
System.NullReferenceException:
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.GetOriginalPath (Microsoft.AspNetCore.Server.IIS, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.InitializeContext (Microsoft.AspNetCore.Server.IIS, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1+<ProcessRequestAsync>d__2.MoveNext (Microsoft.AspNetCore.Server.IIS, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e)
at Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer+<HandleRequest>d__27.MoveNext (Microsoft.AspNetCore.Server.IIS, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60)
To Reproduce
Application experiencing the issue was built from this commit: martincostello/website@ee2ca4ba02823b97062924b7dc8f313e6278a3f8
Expected behavior
HTTP request is processed successfully.
Screenshots
Additional context
Add any other context about the problem here.
Include the output of dotnet --info
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 14
- Comments: 38 (21 by maintainers)
If I understand this thread correctly, we are supposed to wait for another release and in the meantime this is not causing any harm. But it is really distracting to see these false positives where we expect to see only “real” exceptions. Is there some middleware that you can provide to catch this condition? I do not want to filter this on my side, for fear of eating up an authentic failure. TIA
I’m glad this will be addressed in 3.0 but will this be addressed in 2.2.x or 2.x?
Same problem, Azure App Service, asp.net core 2.2 From what I understand - backporting is not happening because “2.2 out of support soon” aka we don’t care enough ? Given that .NET Core 3.0 is not LTS - and LTS release is only scheduled for November 2019 - some people prefer not to move to aspnetcore 3.0 yet. Would you estimate the effort for back porting the fix into 2.2 ?
@jkotalik or we need to find the module that makes this request and make sure it sets
pRawUrl
.@martincostello thank you for your help in figuring this out.
@vsadams could you file another issue saying you are hitting this in 3.0?
+1
Update: For us we had preload enabled flag turned on at the Website level. Disabling this fixed the error
Sorry, I was wrong, this bug was fixed in RS2 update of win 10, AppService is on RS1
Looking at the code in master, it would seem that
GetRawUrlInBytes()
sawNativeRequest->pRawUrl
to be null or empty, and returnednull
, which then isn’t handled byGetOriginalPath()
.https://github.com/aspnet/AspNetCore/blob/85e2147ff037cc9950249fbb9d095ad47ec4184a/src/Shared/HttpSys/RequestProcessing/NativeRequestContext.cs#L141-L151
https://github.com/aspnet/AspNetCore/blob/3c09d644cccdb21801f7a79e1188a1a1212de5d9/src/Servers/IIS/src/Microsoft.AspNetCore.Server.IIS/Core/IISHttpContext.cs#L185-L186