473,386 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

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
3 6614
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Primo | last post by:
Hi, This problem has been frustrating me for days and I hope you experts can help me out. I am trying to run a command, which I would normally run from the command line, from within my C#...
2
by: Grigs | last post by:
Hello, I am attempting to write a Web Method in my Web Service that starts a process that runs the XCOPY command with passed in parameters. It is failing on me through code. However, if I take...
1
by: solex | last post by:
Hello All, Hopefully someone has run into this error. I have written a class(source below) that launches a thread to monitor the StandardOutput of a System.Diagnostics.Process, in particular I...
3
by: Szymon Madejczyk | last post by:
example code: public class envtest { public static void Main() { System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess(); string env =...
1
by: Zeya | last post by:
Scenario: Currently, there is a .lnk file which when executed does the following: (from Property -> target) %windir%\system32\cmd.exe /k set a=something&set...
3
by: Zeya | last post by:
I have created a very simple batch file and trying to retrieve the standard output but everytime I run the code it returns ExitCode as 1. I have created a batch file as simple as ping localhost...
0
by: MirkoGeest | last post by:
(Webmaster: sorry, I posted this first at the General Software Engineering category, but I think this goes here) I'm using Visual Basic with Web Forms on .NET 2003 and I'm experiencing a very...
5
by: Matt | last post by:
Ok so I'm trying to run a simple dos command shell through a VB.NET 2005 program. The oddest thing is happening given the following piece of code: ...
4
by: ceh | last post by:
Hi, I'm using c# vs 2005 win xp pro sp2. I create a cmd prompt with pInvoke via CreateProcessWithLogonW Taskmgr shows that cmd instance running as that user. I type set in that cmd window and it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.