Can't run game in Visual studio

I just recently hard reset my computer and ever since then, I can’t seem to get my game to run in Visual studio. I reinstalled all the necessary components, yet for some reason, my code never gets past the new Game1()

I put some WriteLine statements to see what was happening and it looks like the code never even creates a Game1().

image
image


“Game1 Activated!!!” is never printed to the output.

I’ve even tried creating a new project with the monogame template and I run into the same problem. Any help is appreciated thanks!

1 Like

Put the using () code in a try…catch block and see if it’s throwing an exception.

try
{
    using (blah)
       game.Run();
}
catch (Exception ex)
{
    Debug.WriteLine(ex.ToString());
}

Nothing changes and no output, Visual Studio just keeps running until I press stop even though nothing is happening.

I’m using Version 3.7 with Desktop GL, but I have to imagine it’s similar…

My constructor is defined as:

        public Game1() : base()
        {
            try
            {
// My code similar to yours...
            }
            catch (Exception ex)
            {
// My own logging code here....
            }
        }

The big difference is I’m calling the base constructor… it doesn’t look like you are.

What happens if you run the .exe directly from a cmd window?
(i.e. remove Visual Studio from the equation)

START → cmd
Browse to your game folders bin/debug directory.
Execute:
Eysandia.exe > log.txt

Take a look in log.txt to see what it output.

I just searched my hard drive for Eysandia.exe and ran it, it opened up like normal and then when I went to run it in Visual Studio it ran like normal immediately. Great! However, as soon as I make a change to any file and try to run it, it takes a couple of minutes to open!

So it seems like my problem was not that it wasn’t running but instead that it was taking minutes to start the application.

Is there any reason why Visual studio would take so long to run the program?

There could be many reasons.

I am experiencing performance issues on my 8Mb home PC with Visual Studio 2019 whereas I have none on my work PC (16Mb). It can take a while to Load projects, build and begin debug.

Some things to try:
[Try a bare bones monogame project to see if that takes a long time.
Look in the output tab in Visual Studio to see what it is doing (Menus: View → Output)]
EDIT: I see you did these two above already.

Look in Visual Studio extensions to see if there is anything there that might be slowing it down.
Try your project on a different version of Visual Studio perhaps.

I have only the necessary extensions for monogame. I updated Visual Studio and the program ran immediately after pressing play and kept working until I made any change to the code and saved, then it took a consistent 40 seconds to run every time, even after restarting my computer.

Interestingly after updating Windows, the same thing happened again, it would open up instantly again and again until I made any change to the code and saved. Now it takes 40 seconds to run every time no matter what I do. It’s not even loading content during this time. What is going on?!

EDIT: So weird how it takes excactly 40 seconds every time, regardless of what I’m running in the background. I also have a pretty powerful pc and this same issue occurs with a new project, still 40 seconds on the dot.

I googled 40 seconds and found this:

It’s not a solution but might point you in the right direction.

Also, you could try running a Release build inDebug to see if that has the same issue.

Make sure your final output path isn’t to long either.

I’ve had problems with compiling when having a really long output path

This behavior is very strange, after updating windows thing went great, even after changing code. It worked great for days. However, after changing a static variable in one of my classes the behavior returned and it would take 40 seconds to launch. I updated visual studio and it fixed the problem until I changed some arbitrary piece of code, then it stopped working. This has happened multiple times now, when it breaks, I update windows or VS and it fixes itself (until it breaks again). If there are no update available there is nothing I can do, restarting my computer does nothing.