Microsoft KB Archive/941863

= 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 =

Article ID: 941863

Article Last Modified on 12/3/2007

-

APPLIES TO


 * Microsoft .NET Framework 2.0

-



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:, Key being added:



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



RESOLUTION
To resolve this problem, use one of the following methods:
 * Manually delete the duplicate variable. To do this, follow these steps:
 * In Control Panel, open System.
 * On the Advanced tab, click Environment Variables.
 * 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.

