Process.StartInfo.EnvironmentVariables problem when there are twoenv variables that differ only in l

  • Thread starter Thread starter Szymon Madejczyk
  • Start date Start date
S

Szymon Madejczyk

example code:
public class envtest
{

public static void Main()
{
System.Diagnostics.Process proc =
System.Diagnostics.Process.GetCurrentProcess();
string env = proc.StartInfo.EnvironmentVariables["test"];
}
}

when I compile that code to envtest.exe
and before running it set some env variables that differs only in letter
scope, i.e.

set test=1
set Test=1

I recieve following exception.

Unhandled Exception: System.ArgumentException: Item has already been
added. Key in dictionary: "test" Key being added:
"test"
at System.Collections.Hashtable.Insert(Object key, Object nvalue,
Boolean add)
at System.Collections.Hashtable.Add(Object key, Object value)
at System.Collections.Specialized.StringDictionary.Add(String key,
String value)
at System.Diagnostics.ProcessStartInfo.get_EnvironmentVariables()
at env.Main()
Unknown signal 79

I can catch it but I still cannot get variables value :(

Any idea how to handle that ?

Szymek
 
ProcessStartInfo.EnvironmentVariables is of type
System.Specialized.StringDictionary. The keys in StringDictionary are
case-insensitive. All keys are converted to lowercase before inserted into
the collection. So the only way to solve this is to rename the environment
variables.

Regards, Jakob.
 
Yes I noticed that, problem is not the direct reason of exception but
why it's possible to set variables that differ in case if .net framework
fails after that :(

Szymek

ProcessStartInfo.EnvironmentVariables is of type
System.Specialized.StringDictionary. The keys in StringDictionary are
case-insensitive. All keys are converted to lowercase before inserted into
the collection. So the only way to solve this is to rename the environment
variables.

Regards, Jakob.


:

example code:
public class envtest
{

public static void Main()
{
System.Diagnostics.Process proc =
System.Diagnostics.Process.GetCurrentProcess();
string env = proc.StartInfo.EnvironmentVariables["test"];
}
}

when I compile that code to envtest.exe
and before running it set some env variables that differs only in letter
scope, i.e.

set test=1
set Test=1

I recieve following exception.

Unhandled Exception: System.ArgumentException: Item has already been
added. Key in dictionary: "test" Key being added:
"test"
at System.Collections.Hashtable.Insert(Object key, Object nvalue,
Boolean add)
at System.Collections.Hashtable.Add(Object key, Object value)
at System.Collections.Specialized.StringDictionary.Add(String key,
String value)
at System.Diagnostics.ProcessStartInfo.get_EnvironmentVariables()
at env.Main()
Unknown signal 79

I can catch it but I still cannot get variables value :(

Any idea how to handle that ?

Szymek
 
Back
Top