Reputation: 23
Recently, I added a setup project to my application. In the setup project, I added a registry value that would start my application at windows startup to the HKLM\Software\Microsoft\Windows\CurrentVersion\Run key. When the application runs from this location, it crashes with a System.NullReference exception (it can't find my app.config file, which gets read in a method when the app loads up). I can run the application perfectly fine from the start menu, or from the installed folder. How can I get my application to run at Startup?
Upvotes: 2
Views: 3662
Reputation: 55
Ok. I know this is an old question but the solution is kind of lacking clarity in my opinion. I had the same issue and you don't have to put the app.config (your.exe.config) into the system folder. If you want to keep your program portable and without an MSI you can simply put some lines into the form.
APP_PATH = Application.ExecutablePath.ToString();
Environment.CurrentDirectory = Path.GetDirectoryName(APP_PATH);
Do this early in your form class and it will work.
Upvotes: 1
Reputation: 16174
I believe that will be running with the system folder as the working folder. Either putting the config file in the system folder or ensuring the working folder is set should fix the problem.
Upvotes: 2