By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,302 Members | 3,621 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,302 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.Ad d(String key,
String value)
at System.Diagnostics.ProcessStartInfo.get_Environmen tVariables()
at env.Main()
Unknown signal 79

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

Any idea how to handle that ?

Szymek
Jul 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
The variables are case-insensitive
"Szymon Madejczyk" <sm********@vp.pl> wrote in message
news:cs**********@news.onet.pl...
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.Ad d(String key,
String value)
at System.Diagnostics.ProcessStartInfo.get_Environmen tVariables()
at env.Main()
Unknown signal 79

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

Any idea how to handle that ?

Szymek

Jul 21 '05 #2

P: n/a
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.
"Szymon Madejczyk" wrote:
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.Ad d(String key,
String value)
at System.Diagnostics.ProcessStartInfo.get_Environmen tVariables()
at env.Main()
Unknown signal 79

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

Any idea how to handle that ?

Szymek

Jul 21 '05 #3

P: n/a
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

On 1/14/2005 11:23 AM, Jakob Christensen wrote:
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.
"Szymon Madejczyk" wrote:

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.Ad d(String key,
String value)
at System.Diagnostics.ProcessStartInfo.get_Environmen tVariables()
at env.Main()
Unknown signal 79

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

Any idea how to handle that ?

Szymek

Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.