I have an application that uses Process.Start to execute an exe. It works fine for all the .exe that I have tested except when the .exe has a configuration file where it gets a connectionstring, when this happens I get a System.NullReferenceException. this is my code.
to execute the exe:
string eucApp = @"C:\Temp\app.exe"
startInfo = new ProcessStartInfo(eucApp);
using (Process execProcess = Process.Start(startInfo))
{
execProcess.WaitForExit();
}
then the exe starts and the first thing that does is get the a connection string with this code line
strCadena = ConfigurationManager.ConnectionStrings("ConnectionString")
If I replace this with the connectionstring like this, it works fine
strCadena = "Data Source=HostName;Initial Catalog=MyDB;Integrated security=True"
I would remove the config file and put its values into the .exe code but the trouble is that I have more than 500 .exe’s that uses config files so if any one knows a way to avoide this please tell me!
thanks for your help. I figured out the problem. Somehow the .exe was pointing to the app.config of the aplication that start’s the process. I added this class to the .exe that is developed in VB .Net
I call Change function at the begining of the program
This way it take the right config file