2

I have created a small program in C# WinForms that runs fine when I start it in Visual Studio 2017. But when I build the solution and double click the .exe, nothing happens, no screen appears, even the task manager doesn't see it. No errors. It's like it doesn't do anything! My only guess is that I built it wrong because I used Nuget to install newtonsofts JSON.NET in the solution. Do I need to do anything differently or should just building the solution work?

[solved]

today i learned the difference between the bin and obj folder, thanks to everyone for helping

Laura White
  • 188
  • 2
  • 9
TDM
  • 73
  • 1
  • 1
  • 12
  • Did you do a console application? – Noren Aug 31 '18 at 12:30
  • no, it's a winforms application – TDM Aug 31 '18 at 12:32
  • 1
    What is the name of the exe and what folder is it in? – Crowcoder Aug 31 '18 at 12:37
  • I doubt that it is because of the json.NET Nuget Package. In that case many many users would have already filed bugreports. – Fildor Aug 31 '18 at 12:39
  • 1
    Perhaps it helps if you write an exception handler for `AppDomain.CurrentDomain.UnhandledException` and `Application.ThreadException`. The handler should write the exception into a file. Maybe this helps to find out, what is going on. – ChristianMurschall Aug 31 '18 at 12:39
  • Can you see the Application's name in Task Manager? – Fildor Aug 31 '18 at 12:40
  • Did you check event log for exception, it may help you to narrow down exact issue your app has. Most probably missing dll or unhandled exception. – Dipen Shah Aug 31 '18 at 12:42
  • Are you sure you're running the correct exe and not the one that ends with `.vshost.exe`? – Reinstate Monica Cellio Aug 31 '18 at 12:49
  • @Crowcoder the name is CrewBirthdayEditor.exe, and it is in the obj/debug folder of the project – TDM Aug 31 '18 at 12:56
  • @Fildor nope, it isn't in the taskmanager – TDM Aug 31 '18 at 12:58
  • 2
    @Vecro `bin\debug`? `bin\release`? Are you running the one that is built by your currently selected build configuration? – Crowcoder Aug 31 '18 at 12:58
  • @Vecro - Don't run from obj\debug... that's for intermediate build files. Run from bin (Release, Debug, or whatever configuration you built it for). – Broots Waymb Aug 31 '18 at 12:59
  • For future reference, one good way of investigating console application issues when you see no console, is to start the application via Command Prompt, as it will launch your application in the console window and keep the output if it crashes. Alternatively pipe it out to a file. – ColinM Aug 31 '18 at 13:08

5 Answers5

3

Based on your comment:

it is in the obj/debug folder of the project

It sounds like you're running the wrong .exe. The obj folder is used for temporary/misc. files from the build process (see What is obj folder generated for?).

Instead, you want to run the exe within bin\Debug, if "Debug" is the configuration you're building for. You can see which configuration at the top of VS.
enter image description here

Like others have also mentioned, make sure that Newtonsoft.Json.dll is being copied to that output directory as well. Programs and their dependencies need to be together, generally speaking. Otherwise, your exe will not know where to find the JSON code it needs to function.

99% of the time, you should pretend the obj directory isn't even there.

If that still isn't pointing you in the right direction, run the app from a command window. Any exception should get printed to it and the window will remain open for you to examine (and this has the benefit of not needing any additional logging or exception handling code to see this error).
For example, I wrote up a bad application that get a NullReferenceException in a method called Test that is called from Main. As you can see, the stacktrace is easily visible, even though my app has crashed (credit to ColinM for bringing this up originally).
enter image description here

Broots Waymb
  • 4,713
  • 3
  • 28
  • 51
2

I believe that there's a problem with the startup module. Follow the steps below

  1. Open your Solution in visual studio
  2. Double click on properties

    enter image description here

  3. Select output type to Windows Application

  4. Make sure to set the startup object as follows

    enter image description here

I hope it helps

Yasirmx
  • 417
  • 3
  • 9
2

For future reference, yet another reason (that I have experienced) can be

System.Diagnostics.Debug.Assert();

statements. In my case, the program executed normally when started from VS but when I run it by clicking its .exe (created in the Debug Mode) then it hung/freezed. No exceptions, no printed logs. Frustrating. Then I checked the Windows Event Viewer (Our true friend). It explicitly displayed the problem and the culprit was a Debug.Assert() statement.

The lesson learned again: Check

Windows Event Viewer > Windows Logs > Application

especially when your app hangs/freezes/deadlocks or when no app logs are available.

Mustafa Özçetin
  • 1,893
  • 1
  • 14
  • 16
1

I think there is only one reason

There is a command line argument predefined in Visual Studio. Your application uses this argument to be executed, without it, it closes itself too quickly and you even can't see your application opened.

Right click on your project in VS -> Properties -> Debug and see if there is a value in command line arguments

Fildor
  • 14,510
  • 4
  • 35
  • 67
Antoine V
  • 6,998
  • 2
  • 11
  • 34
  • there is no value in the command line arguments, should there be? if so what should it be? – TDM Aug 31 '18 at 12:54
  • 2
    Since when do WinForms applications come with a predefined argument in that window? – Broots Waymb Aug 31 '18 at 12:57
  • +1 It happend to me that I just forgot about a command line parameter I had implemented and entered into the debug configurations. – Kit Fisto Dec 26 '19 at 16:04
1

exe and their supporting files should be in the bin folder. Do not copy only exe from bin folder and try to run it. It is a good idea to write some exception code to get the detail.

Fildor
  • 14,510
  • 4
  • 35
  • 67
chandan
  • 69
  • 2
  • @Vecro - I think he's telling you to make sure that supporting libraries (Newtonsoft.Json.dll) are also in the bin folder. – Broots Waymb Aug 31 '18 at 12:56