I have a C# project that compiles normally. When I run the project via Visual Studio’s IDE it runs fine and ends cleanly. However when I navigate to the project directory and attempt to run the program by double clicking the “exe” file or referencing it via the run window it errors out.
I have narrowed the problem down to
Console.WriteLine("output ->" + any_variable);
For some reason if I print any variable using the console.writeline the application will error if ran as described earlier.
If I take this line out, the executable created by the Visual Studio will run just fine if i double click on it. I’m really confused by this. My goal here is to create this command line project as a scheduled task.
I’d assume the error not having anything to do with
WriteLineor even aConsole. While a common a difference between running from IDE and running from double-clicking might be the rights (i.e., you may start the IDE as admin, or the location that you are writing/reading from/to is different and has different ACLs attached to it), thiis doesn’t seem to be the case here.To catch your actual error, compile into debug mode. Start your application (possibly with a message box of some kind). Start the IDE and select Debug and Attach to process (you have all the time if you pause your app with a message box). Select your process. Run until you receive the error. You should now receive the error in the IDE, even though the app is run from double clicking the EXE. You can see the stack and debug as you would normally do.
My guess? The variable you’re printing does something that raises the error.
Altenatively: a simple try/catch around the offending statement plus a messagebox with the
Exception.Messageshould give you some more intel too.