question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Internal NullReferenceException in OwinHttpListener.cs on .Net(Core) 5

See original GitHub issue

I am porting a .NET Framework 4.7 application to .NET 5 which uses Microsoft.AspNet.WebApi.OwinSelfHost 5.2.7 (which depends on Microsoft.Owin.Host.HttpListener).

When running my app in VisualStudio I can see NullReferenceExceptions logged in DEBUG outputs. When using decompile feature I can see the source from accessing the 2 static fields:

https://github.com/aspnet/AspNetKatana/blob/1fba52940ccfa74470c75c627699baca13aadfa4/src/Microsoft.Owin.Host.HttpListener/OwinHttpListener.cs#L30-L31

They depend on reflection of non-public fields.

The NRE itself happens at line 226 when accessing text = (((string)CookedPathField.GetValue(request)) ?? string.Empty);. For mono there seems to be another approach used.

Can you please review the reflection based access to the 2 fields using .NET 5?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Tratchercommented, Jan 9, 2021

Unlike ASP.NET 4.x, ASP.NET Core fully supports self-host scenarios. Much of ASP.NET Core was derived from these Microsoft.Owin libraries.

This: https://github.com/MediaPortal/MediaPortal-2/blob/8234fb872b2f1b59338468cbd57d2127edff0388/MediaPortal/Source/Core/UPnP/Infrastructure/Dv/UPnPServer.cs#L185

Becomes something like: https://github.com/dotnet/aspnetcore/blob/b143a974a5574b9fccedbbe2389aabbfd48fdb6f/src/Hosting/samples/GenericWebHost/Program.cs#L14-L28 but change RunAsync to StartAsync since it looks like you want to start multiple servers.

0reactions
morpheusxxcommented, Jan 13, 2021

https://github.com/aspnet/AspNetKatana/blob/1fba52940ccfa74470c75c627699baca13aadfa4/src/Microsoft.Owin.Host.HttpListener/OwinHttpListener.cs#L289 I changed this code line to: if (IsMono || CookedPathField == null) and it fixed my issue. I didn’t find other issues yet.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is [Owin] throwing a null exception on new project?
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: An unhandled exception was ...
Read more >
NullReferenceException Class (System)
Initializes a new instance of the NullReferenceException class with a specified error message and a reference to the inner exception that is the...
Read more >
System.NullReferenceException while trying to load a view
I am trying to load DataMgmt.cshtml view by clicking on a link from my _Layout page but the page which should be loaded...
Read more >
Friends Don't Let Friends Swallow NullReferenceException
ASP.NET MVC framework is swallowing NullReferenceException without you even noticing. While it might slow the page load a little bit, it is not...
Read more >
Object reference not set to an instance of an object.
It simply means that some member/variable of some reference type is dereferenced by using and of its instance (non-static) members, which ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found