This project is read-only.

Strange NullReferenceException [v2.0]

Jul 8, 2011 at 9:36 AM

While investigating this issue I came across another strange bug. Sometimes the Request's ContentLength setter wouldn't throw the 'Too large body' exception, but

500 - Object reference not set to an instance of an object.

System.NullReferenceException: Object reference not set to an instance of an object.
   at HttpServer.Messages.Request.set_ContentLength(NumericHeader value) in D:\Projekte\Visual Studio\OmegaHTTPd\HttpServer\Messages\Request.cs:line 244
   at HttpServer.Messages.Request.Add(String name, IHeader value) in D:\Projekte\Visual Studio\OmegaHTTPd\HttpServer\Messages\Request.cs:line 188

It seems that the static getter Server.Current in

if (_contentLength.Value > Server.Current.MaxContentSize)

returns null. To reproduce the exception, create a test.html file like

<form method="post" action="test.html">
<input type="text" id="test" name="test" value="Test" />
<input type="submit" value="Test" />
start the server and navigate to that file. Then close the server, start it again and without refreshing the page, submit the form.

The problem seems to be the servers ThreadStatic attribute

[ThreadStatic] private static Server _server;
Don't know what's going wrong there, since the server clearly isn't null (and _server gets set in the constructor). If you know a solution, please let me know. Could be something specific to .NET threading!?

Jul 8, 2011 at 9:39 AM

Yes, it's related to threading. It should be set each time a new request is received, but I guess I set it too late sometimes.

Today is my last day before vacation. So I'll have some more time to spend on the project soon. I've been swamped with work for a couple of months.

Jul 8, 2011 at 10:00 AM

Thanks for the fast reply. Just googled a bit and found this and this - but the solutions are .NET 4 specific ...

Nov 8, 2011 at 3:23 AM

I need a fix to this.

Jan 15, 2012 at 6:08 PM

Hi there,

Any one found a solution?



Jan 31, 2012 at 8:16 PM

Fixed in the latest trunk. I introduced a property called MaxContentSize in Server class, but seemed to forget to initialize it. Hence all bodies were too large.