Article ID: 941863 - Last Review: December 3, 2007 - Revision: 1.2

You may receive a System.ArgumentException exception when you use the XmlSerializer constructor to serialize a custom data type in a .NET Framework 2.0 application

Expand all | Collapse all

SYMPTOMS

Consider the following scenario:
  • In a Microsoft .NET Framework 2.0 application, you use the XmlSerializer constructor to serialize a custom data type.
  • You do this by using an environment variable.
In this scenario, you receive the following exception error message:
System.ArgumentException Item has already been added. Key in dictionary: temp, Key being added: temp

CAUSE

This problem occurs because two environment variables have the same name. For example, one environment variables is named temp, and another is named TEMP.

RESOLUTION

To resolve this problem, use one of the following methods:
  • Manually delete the duplicate variable. To do this, follow these steps:
    1. In Control Panel, open System.
    2. On the Advanced tab, click Environment Variables.
    3. Perform one of the following actions:
      • Select the duplicate environment variable, and then click Delete.
      • Click Edit to rename the duplicate variable.
  • Use the Setx.exe tool in a program to delete the duplicate variable.
  • Use the Sgen.exe tool to generate serialization assemblies. This method helps avoid duplicate environment variables.

STATUS

You cannot use duplicate environment variables.

This behavior is by design.

REFERENCES

For more information about environment variables, click the following article numbers to view the articles in the Microsoft Knowledge Base:
310519  (http://support.microsoft.com/kb/310519/ ) How to manage environment variables in Windows XP
311933  (http://support.microsoft.com/kb/311933/ ) How to specify environment variables in project settings by using Visual C++ .NET or Visual C++ 2005
195050  (http://support.microsoft.com/kb/195050/ ) How to clear environment variables using Setx.exe
For more information about the Sgen.exe tool, visit the following Microsoft Developer Network (MSDN) Web site:
http://msdn2.microsoft.com/en-us/library/bk3w6240(VS.80).aspx (http://msdn2.microsoft.com/en-us/library/bk3w6240(VS.80).aspx)

APPLIES TO
  • Microsoft .NET Framework 2.0
Keywords: 
kbtshoot kbxml kbprb kbexpertiseadvanced kbdotnetservices KB941863
 

Article Translations

 

Related Support Centers