I compiled my application to use .NET Framework 4 because I need this to work on XP and Server 2003 that does not support .NET Framework 4.5. The issue is it now runs fine on the XP and 2003 servers but not on my Server 2012. Server 2012 has .NET 4.5 and from what I have read .NET 4.5 is backwards compatible with .Net 4
Below it the error I receive on my 2012 Server:
Unhandled exception has occurred in your application if you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.
The System cannot find the file specified.
Details:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at MyApplication.Form1.DirectoryExporter_Click(Object sender, EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18449 built by: FX451RTMGDR
CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v4.0.30319/mscorlib.dll
----------------------------------------
MyApplication
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/administrator.DM/Desktop/MyApplication.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.0.30319.18408 built by: FX451RTMGREL
CodeBase: file:///C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Here is the code that is being called at this time:
public string get_regValue(string userroot, string subkey, string keyname, string app)
{
string userRoot = userroot;
string subKey = subkey;
string keyName = userRoot + "\\" + subKey;
string regValue = (string)Registry.GetValue(keyName, keyname, null);
regValue = regValue + app;
return regValue;
}
private void DirectoryExporter_Click(object sender, EventArgs e)
{
// Button to Launch the Directory Exporter
string regKey;
RegistryKey openKey = Registry.LocalMachine.OpenSubKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Dell");
// Checks for key, if null (empty) get 32 bit key
if (openKey == null)
{
// 32 bit key
regKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Dell";
}
else
{
// 64 bit key
regKey = "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Dell";
}
var regvalue = get_regValue(regKey, "Migrator for GroupWise", "AdminInstallDir", "gwdirapp.exe");
Process.Start(@regvalue);
}
I strongly suspect this has nothing to do with the version of .NET you're using. After all, from the stack trace you can clearly see that your code is executing:
at MyApplication.Form1.DirectoryExporter_Click(Object sender, EventArgs e)
I suspect that the issue is one of permissions - that whatever you're trying to do is failing under Windows Server 2012 due to it running in a more locked down environment.
Alternatively, it may be that you're trying to start a process that exists on your development machines, but not on the server. We can't really tell without seeing the code - but you should basically look carefully at what you're doing in DirectoryExporter_Click
, particularly when you call Process.Start
. Examine which executable you're trying to run, then check that it's present on the server, and that the user you're running as has permission to execute it.
See more on this question at Stackoverflow