MSDN documentation can be incomplete.

Posted August 23rd @ 12:14 am by aaron

Well, incomplete in my opinion anyway.

A co-worker was having a problem with his in-process HTTP server written using the very cool HttpListener class available in .NET 2.0 (on Win2k3 and WinXP SP2 only). In his code he was attempting to enable chunking of the response by setting the HttpListenerResponse.SendChunked property to true. Great! But it didn’t chunk. Why? Because his code looked like this:

HttpListener listener; // Created elsewhere
HttpListenerContext context = listener.GetContext();
// Open a file/stream/whatever, etc.
System.IO.Stream stream; // = …
context.Response.SendChunked = true;
context.Response.ContentLength64 = stream.Length;
// etc.

According to the documentation, there’s nothing wrong with that. What they don’t tell you, however, is that SendChunked and ContentLength64 are mutually exclusive. Setting one negates the effect of the other. After a couple of minutes of reflection (both mentally, theoretically, and most importantly programmatically) on the subject, this fact started rising to the surface.

To me, that’s worth putting in at least a comment in the documentation.

1 Trackbacks/Pingbacks

  1. Pingback: More fun with documentation | Aaron Lerch on November 13, 2007

Leave a comment

OpenID Login

Standard Login

Options:

Size

Colors