Serialization Temporary Assemblies
The XmlSerializer is one of the options WCF provides for mapping between XML and strongly-typed objects. An XmlSerializer is generally preferred over other serialization approaches, such as a DataContractSerializer, when the description of the type already exists as an XML schema.
The conversion process for XmlSerializer relies on decorating a type with metadata attributes that describe how the type mapping should take place. These metadata attributes link together fields in the type with elements and attributes in the XML schema.
Internally, XmlSerializer analyzes the metadata attributes that you provided on the type to automatically construct the appropriate serialization code. Code generation greatly speeds up the serialization process but requires building some temporary classes and assemblies to host the code. Since these assemblies need to live somewhere, they are placed into the standard system temporary directory. Most normal user accounts have access to this directory but sometimes you want to run your application using an account with very few privileges. An anonymous or restricted service account may not be able to write to the temporary directory, causing serialization to fail.
There are two ways that you can adjust the interaction between the application account and the generation of temporary assemblies.
The first approach is to grant the application account read and write privileges to the temporary directory. If you don't know where the system temporary directory is located, the error message that you got when serialization failed should include the file path where XmlSerializer was expecting to find the generated code.
The second approach is to change where XmlSerializer writes the generated code to be a location where the application account has the appropriate privileges. You can change the location for generated code by adding a serialization section to your configuration file:
<system.xml.serialization>
<xmlSerializer tempFilesLocation="an absolute path of your choice"/>
</system.xml.serialization>
Next time: Acting on Open
Comments
Anonymous
June 16, 2008
Inside of a service method, how do I know where the message was delivered? Without defining what distinguishesAnonymous
June 16, 2008
Using sgen.exe might work too.Anonymous
June 17, 2008
Can I add this config file section into an existing config file for a console app (eg fred.exe.config) ? If I just drop it into my previously working file it causes an error: Unrecognized configuration section system.xml.serialization ....etc Is it me or my config file that's missing something ? BTW it's possible to achieve the same redirection by setting windows variable TMP before running the exe but it means you have to do it manually or call the exe from a cmd file.Anonymous
June 17, 2008
You might not have the update that includes this configuration setting. It was added after the 2.0 release. http://support.microsoft.com/?kbid=934529Anonymous
April 18, 2009
Sometimes customers open technical support cases because of this (apparently simple) issue: “System.Web.Services.