Skip to content

April 19, 2010

CS0016: Could not write to output file with SharePoint

I was at a client today and they were having all sorts of errors in SharePoint. One of them was that central administration pages were returning ‘unknown error’. When I turned on debugging I saw a server error in application with these details…

CS0016: Could not write to output file ‘c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\242d0ff4\3604ddcb\en-US\App_GlobalResources.aaqxxojv.resources.dll’ — ‘The directory name is invalid.

It was quick enough to find a Microsoft KB article (825791) for CS0016. It points to the fact that there may be a bad TMP or TEMP directory setting. We went into the service and manually set the TMP and TEMP variables in the profile. However, the problem didn’t go away. After further digging we changed the TMP and TEMP at the system level – because we discovered that someone had set the system values to an invalid directory. When we changed the system level setting to a valid directory the problem went away.

XML Invalid Data and Byte Order Marker

While working on some InfoPath and Workflow I got bit again by the Byte Order Marker and I felt like I should document what’s going on. I was getting an exception… “The data at the root level is invalid. Line 1, position 1.” Here’s why:

The XML encoding that InfoPath uses is UTF-8. UTF-8 will make the first byte of the file (when decoded with UTF-8) a byte order marker. When XmlDocument sees this it’s confused. It expects the XML tag to appear at the very first character of the string you provide it. It’s simple to deal with – but frustrating to find. This code create a new XmlDocument, extracts the file contents from SharePoint, and loads it into the document.

XmlDocument wfDoc = new XmlDocument();

Byte[] fileBytes = wfFile.OpenBinary();

string fileAsString = (new System.Text.UTF8Encoding()).GetString(fileBytes);

wfDoc.LoadXml(fileAsString.Substring(1)); // SKIP Byte Order Marker @ beginning of file

A better approach is to hand off the stream to XmlDocument:

XmlDocument wfDoc = new XmlDocument();

using (Stream wfFileStrm = wfFile.OpenBinaryStream())




This will load fine without stripping the Byte Order Marker – but in my case, this isn’t supported in SharePoint Sandbox code because the System.IO.Stream type isn’t allowed.

Recent Posts

Public Speaking