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 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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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#...
|
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...
|
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...
|
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 =...
|
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...
|
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...
|
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...
|
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:
...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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,...
|
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...
| |