Welcome to MSDN Blogs Sign in | Join | Help

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

Published Monday, June 16, 2008 5:00 AM by Nicholas Allen
Filed under: ,

Comments

Monday, June 16, 2008 11:57 AM by Nicholas Allen's Indigo Blog

# You Are Here

Inside of a service method, how do I know where the message was delivered? Without defining what distinguishes

Tuesday, June 17, 2008 2:46 AM by Lucian Bargaoanu

# re: Serialization Temporary Assemblies

Using sgen.exe might work too.

Tuesday, June 17, 2008 11:20 AM by A Nonny-No

# re: Serialization Temporary Assemblies

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.

Tuesday, June 17, 2008 8:56 PM by Nicholas Allen

# re: Serialization Temporary Assemblies

You might not have the update that includes this configuration setting.  It was added after the 2.0 release.

http://support.microsoft.com/?kbid=934529

Saturday, April 18, 2009 9:34 AM by Elementary, my dear Dr. Watson

# Could not find file ‘C:\WINDOWS\TEMP\..dll’

Sometimes customers open technical support cases because of this (apparently simple) issue: “System.Web.Services.

New Comments to this post are disabled
 
Page view tracker