Error Saving Site as Template

The reason for this post is to hopefully help other users who may have come across the error generating solution files in temporary directory error when attempting to save a site as a template.

Error generating solution files in temporary directory

Error generating solution files in temporary directory

I came across the above error when enabling auditing against a custom content type and subsequently tried to save the site as a template. Looking through the entries in the ULS (unified logging service) log I found the following couple of errors:

SPSolutionExporter: System.InvalidOperationException: The Writer is closed or in error state.
System.InvalidOperationException: Error generating solution files in temporary directory.

Nothing too obvious here, except that there was a problem during the processing of the site, which I’d guess was more than likely a serialisation issue.

Lots of debugging and trial and error later, I discovered that the piece of code I had in a feature event receiver was causing the problem. The code enabled auditing against the custom content type when the feature was activated and bypassing this on activation allowed the site to be saved as a template without error. The problem was to do with how I enabled auditing or possibly with the custom content type or was an inherit problem with the auditing policy itself.

I decided to completely remove my solution and re-created the site collection with a blank team site. From here, I enabled the SharePoint Server Standard Site Collection features site collection feature, which is required to enable the information management policy setting in the site. Once enabled, I edited the Item content type and enabled auditing.

Enable Auditing

Enable Auditing

When I tried to save the site as a template I got the same error, so it can’t have been anything to do with my content type or how I enabled auditing through the feature event receiver. Disabling and\or deleting the policy doesn’t remove the error and saving the template is still not possible.

In fact the only way I’ve found it possible to save the site after doing this is to remove the content type itself, which for the Item content type isn’t a good idea 🙂 Well, it’s not a good idea for any content type to be honest.

So far, I haven’t found a way around this issue or a decent way of rolling back to a state where saving is still possible without the need to delete things. If I find a resolution for this I’ll be sure to post an update.

This entry was posted in SharePoint and tagged , . Bookmark the permalink.

2 Responses to Error Saving Site as Template

  1. Ashraf says:

    just to share with you, after lots of workaround i am also stuck on this. thanks

  2. Daniel says:


    This may be a Site Collection specific issue rather than farm or a SP1/CU problem i.e. perhaps a feature has not been enabled. The reason I say this. I picked an pretty innocuous site on sites/sc1 to create a template and got the error.

    I went to /sites/sc2 and picked a site at Random and this worked fine. I haven’t tried another site /sites/sc1 but I can if his helps with the investigation.

    I enabled the managed columns feature on a site in /sc1/ the other day which I pretty sure was at the site collection level but for the life of me I can’t remember today…

    Good luck


Leave a Reply to Daniel Cancel reply

Your email address will not be published. Required fields are marked *

Solve the maths problem shown below before posting: *