Erik B
Erik B

Reputation: 51

C# Winform App Not Working On Other Computers (Mysterious Hang On Startup)

I made a winforms app in Visual Studio. This app is a simple Hello World app that changes a button's text to "Hello World" when pressed.

Here is the code below:

using System;
using System.Windows.Forms;

namespace HelloWorld
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            try
            {
                InitializeComponent();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                button1.Text = "Hello World";
                button1.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
    }
}

When I try to open this program on my development computer, everything works fine. I tried running on 10 different Windows PCs with .NET 3.5 installed (my targeted platform) and everyone of them does the same thing.

Once I double click, or right click and run as administrator, it seems like the application does nothing, but I can tell it's doing something because the mouse cursor changes to a wait cursor... and it does this indefinitely. It also spawns 3 processes of the app's name that cannot be terminated. No Error or "this application has stopped working" is ever thrown.

In addition, I am unable to create crash dumps using task manager, process explorer, debugdiag, or procdump. When I try to get a dump using process explorer... it will say "Only part of a ReadProcessMemory". When I try to create with debugdiag... the dumps are 0 bytes and fail when analyzing. When I try to get a dump with procdump... it will just sit there forever.

I even tried trying to force some sort of error this way...

using System;
using System.Windows.Forms;

namespace HelloWorld
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            try
            {
                System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                System.Windows.Forms.Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(OnGuiUnhandedException);
                AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1());
            }
            catch (Exception e)
            {
                HandleUnhandledException(e);
            }
            finally
            {
                // Do stuff
            }
        }

        private static void HandleUnhandledException(Object o)
        {
            // TODO: Log it!
            Exception e = o as Exception;

            if (e != null)
            {

            }
        }

        private static void OnUnhandledException(Object sender, UnhandledExceptionEventArgs e)
        {
            HandleUnhandledException(e.ExceptionObject);
        }

        private static void OnGuiUnhandedException(object sender, System.Threading.ThreadExceptionEventArgs e)
        {
            HandleUnhandledException(e.Exception);
        }
    }
}

Later I tried putting a MessageBox and a return in the program.cs at the beginning of the Main() function. It still did the same thing on all 10 PC's. So I figured that when the program is ran, it never actually hits this:

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());

After all this, I wonder if it has to do anything with my Visual Studio setup or configuration.

Steps I took:

  1. I created new winforms app in Visual Studio 2015
  2. I changed .Net platform to 3.5
  3. I coded simple app as show above
  4. Under configuration manager I changed to x86
  5. I built in debug and release mode

After this, I tried 3 deployment methods:

All of these did not work. They all do the same thing... spawn 3 processes with the same name that cannot be terminated unless I restart my computer. Cannot create dumps to see what the problem is. Hangs indefinitely when I run and does not display any errors or windows. ClickOnce and InstallShield never go through any sort of wizard. They just hang indefinitely too...

I tried targeting the 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.2 .NET versions too on my friends' PC and I am getting the same situation. These PCs are windows 7 and 8.1. Why is my simple HelloWorld application doing this? Is it something in my configuration on Visual Studio?

Upvotes: 3

Views: 2424

Answers (1)

Erik B
Erik B

Reputation: 51

I have seemed to solved the issue finally. The problem was that when I created my new project. It always targeted 4.5.2. Then I would go to the project settings and change the framework version from there.

When I select any other framework other than 4.5.2 before I create the project, it works.

I do not know why, but it fixed it for me.

Upvotes: 1

Related Questions