Friday, January 29, 2010

CF HttpWebRequest does not allow writing to the request stream by default

While trying to send data via a request stream, I ran into this error in the compact framework:
ex = {"Either ContentLength must be set to a non-negative number, or SendChunked set to true in order to perform the write operation when AllowWriteStreamBuffering is disabled."}

This was a bit confusing since I didn't get this error when running from a windows client.  I finally figured out that I have to allow writing to the stream:

private void SendData(WebRequest request, object dto)
   // I had to add this for the CF framework. It isn't true by default.
   if (request is HttpWebRequest)
      ((HttpWebRequest) request).AllowWriteStreamBuffering = true;

   using (Stream requestStream = request.GetRequestStream())
         if (IsJsonRequest(request))
            SendDataAsJson(requestStream, dto);
        else SendDataAsXml(requestStream, dto);

MSUnit toolbar does not work or is grayed out

If you have a library with MSUnit tests in it (probably because you converted MBUnit or NUnit tests to MSUnit tests) and the MSUnit toolbar will not work (stays grayed out), you are probably missing the ProjectTypeGuids. The line your missing from the library project file in the top most PropertyGroup is this one:


The line above identifies the project as a test project ({3AC096D0-A1C2-E12C-1390-A8335801FDAB}) in the C# ({FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}) language.

Reference that I found after the fact: