I ran into the above error when saving a collaboration site as template using the OOTB SharePoint 2010 UI. The full stack is as below. This post describes how I solved this issue.

SPSolutionExporter: System.InvalidOperationException: The Writer is closed or in error state. at System.Xml.XmlWellFormedWriter.AdvanceState(Token token) at System.Xml.XmlWellFormedWriter.WriteEndElement() at Microsoft.SharePoint.ScopedXmlWriterElement.Closer(XmlWriter writer, ScopedObjectUsage`1 wrapper) at Microsoft.SharePoint.ScopedObjectUsage`1.Dispose(Boolean isDisposing) at Microsoft.SharePoint.ScopedObjectUsage`1.Dispose() at Microsoft.SharePoint.SPSolutionExporter.ExportFields(SPFieldCollection fields, String partitionName) at Microsoft.SharePoint.SPSolutionExporter.ExportLists() at Microsoft.SharePoint.SPSolutionExporter.GenerateSolutionFiles() at Microsoft.SharePoint.SPSolutionExporter.ExportWebAsSolution()

Note that one of the calls in the stack is SPSolutionExporter.ExportFields(SPFieldCollection, ..). Using ILSpy you can see that this is being called for SPWeb.AvailableFields where SPWeb is the site you are saving. This means all fields “available” to the site are being exported.

First, change the logging level in Central Admin so we can get more info about what’s going on. When saving a site as template, activities are logged under the category SharePoint Foundation \ General. Change this to Verbose.

Run ULS Viewer and perform the save again. Using the correlation ID of the error, you will now see these two additional lines in the ULS just before the error:

The first line indicates the physical location where the WSP (i.e. your site template) is being saved. The second line indicates the file that is causing the error. Note ‘TEST2ListInstances‘ – ‘TEST2’ is the name I specified for my site template.

Go to the physical location and open the ElementsFields.xml file. In my case, this file was incomplete and therefore the XML is malformed. The last field (i.e. the incomplete field) in the file appeared as below:

The problem is the xmlns=”” part of the CHOICE element. I edited the SchemaXml property of the field straight in SharePoint Manager (do this in Dev environment only!!) and removed the xmlns=”” part. I was then able to successfully save the site as template.

There is more work to be done at this point, because if you now edit the field using the OOTB SharePoint UI, it will add the xmlns=”” part back in (even if you just click OK and didn’t make any update using the SharePoint UI).

The offending field was deployed through XML. I went back and look at the source code and both the Field and the CHOICE elements do not have the xmlns attribute specified. Not sure how that attribute made it into the SharePoint DB – another mystery.

Advertisements

Share this:

Like this:

LikeLoading...

Related

About Bernado

Based in Australia, I am a freelance SharePoint and Dynamics CRM developer. I love developing innovative solutions that address business and everyday problems. Feel free to contact me if you think I can help you with your SharePoint or CRM implementation.