I have an application, designed to run on a 24/7 server. Localy tested everything just works smooth and as expected. Deployed to the Windows Server 2012 R2 - I get an exception, whenever the main task (threaded) starts.
On the Server i have obviously no Visual-Studio, so I cannot debug ig. I Just get an Ugly Windows-Dialog, stating that "{ApplicationName} has stopped working.".
In the EventViewer i found an Entry, indicating a position of the error.
The EventLog says:
Application: MyApplicationBackend.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
Stack:
at Application.Name.SomeClass..ctor()
at Application.Name.SomeThread()
at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
at System.Threading.ThreadHelper.ThreadStart()
Well, inside the constructor of SomeClass there is nothing critical going on - just a mysql database connection, like this, (Where cfg. is a singleton, holding Configuration values):
//Connecto to server.
String connectionString = "server=" + cfg.DatabaseServer + ";user=" + cfg.DatabaseUser + ";database=" + cfg.DatabaseName + ";port=" + cfg.DatabasePort + ";password=" + cfg.DatabasePassword + ";";
mysqlConnection = new MySqlConnection(connectionString);
- MySQL Connector .Net 6.8.3 is installed
- Code is going to connect to a remote database (local network)
- Code works perfect on my local machine. (Same network)
This raises 2 Questions:
1.) Can I (and if, how?) handle Exceptions that appear within any level of nested threads from the main-thread?
2.) What kind of file could it be, that is not found (regarding this 2 lines of code)? Localy its working fine (soure is located on a network share), but when executing from my server i get this exception (Using the SAME exectuable from the SAME network share)
Just used some MessageBoxes to debug the stuff... Ultimately it looks like the following:
public class class1{
private void SomeThread(){
MessageBox.Show("before con");
DbCon dc = new DbCon();
MessageBox.Show("after con");
}
}
and
public class DbCon{
public DbCon(){
MessageBox.Show("inside");
String connectionString = "server=" + cfg.DatabaseServer + ";user=" + cfg.DatabaseUser + ";database=" + cfg.DatabaseName + ";port=" + cfg.DatabasePort + ";password=" + cfg.DatabasePassword + ";";
mysqlConnection = new MySqlConnection(connectionString);
}
}
I receive the Message "before con" - And then the exception is thrown... Like it just does not find DbCon
-Class - but this is part of the executable - and could not trigger a File-Not-Found-Exception
??!! (AND works on local machine :-( ) ...