[Mono-bugs] [Bug 72260][Nor] New - SetEnvironmentVariable win32 API has no effect on Mono

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sun, 6 Feb 2005 08:46:39 -0500 (EST)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by gert.driesen@pandora.be.

http://bugzilla.ximian.com/show_bug.cgi?id=72260

--- shadow/72260	2005-02-06 08:46:39.000000000 -0500
+++ shadow/72260.tmp.28090	2005-02-06 08:46:39.000000000 -0500
@@ -0,0 +1,68 @@
+Bug#: 72260
+Product: Mono: Runtime
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: gert.driesen@pandora.be               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: SetEnvironmentVariable win32 API has no effect on Mono
+
+Description of Problem:
+
+The SetEnvironmentVariable win32 function allows you to set an 
+environment variable for the current process. However, calling this 
+function from an assembly on Mono/Windows does not seem to have any 
+effect. The SetEnvironmentVariable function returns success, but 
+Environment.GetEnvironmentVariable return null.
+
+Steps to reproduce the problem:
+
+Compile and run the following code snippet on Mono/Windows:
+
+using System;
+using System.Runtime.InteropServices;
+
+public class EntryPoint {
+  public static void Main() {
+    const string envVarName = "Foo";
+
+    if (!SetEnvironmentVariable(envVarName, "Some Value")) {
+      Console.WriteLine(Marshal.GetLastWin32Error());
+      return;
+    }
+
+    string envValue = Environment.GetEnvironmentVariable(envVarName);
+    if (envValue == null) {
+      Console.WriteLine("Environment variable \"{0}\" is not set.",
+        envVarName);
+    } else {
+      Console.WriteLine("Environment variable \"{0}\" is set to \"{1}\".",
+        envVarName, envValue);
+    }
+  }
+
+  [DllImport("kernel32.dll", CharSet=CharSet.Unicode, SetLastError=true)]
+  private static extern bool SetEnvironmentVariable(string lpName, 
+    string lpValue);
+}
+
+Actual Results:
+
+Environment variable "Foo" is not set.
+
+Expected Results:
+
+Environment variable "Foo" is set to "Some Value".
+
+How often does this happen? 
+
+Always.