Startup crash with the published windows build

Hi There,

With Monogame 3.8.4.1 on .Net 8, when I publish my app to a folder, with any kind of combination I tried so far, it crashes immediately at the startup when I try to run the exe with this error :

System.NullReferenceException: Object reference not set to an instance of an object.
   at MonoGame.Framework.WinFormsGameWindow.OnDeactivate(Object sender, EventArgs eventArgs)
   at System.Windows.Forms.Form.WmActivate(Message& m)
   at Microsoft.Xna.Framework.Windows.WinFormsGameForm.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)

I can make debug and/or release builds in Visual Studio 2022 and they work fine whether inside Visual Studio or if I try to run the exe from file explorer. Anybody know what might be wrong?

Thanks,

Ă–zden

I always build my installers from the output directory instead of publishing the app for Windows.

There is an optimization step that excludes non-referenced assemblies needed by reflection(AOT).

—

It not advised to use the .NET Publish to distribute your game.

I am unable to post the link as a “new user”.

What is the command you are using to publish? I use dotnet publish all the time for my game releases.

Well, as a good news it works now! After 2 submissions to Steam, which failed because of not being able to install .Net framework 8 without a prompt, I decided to do give another try, saw that the build configuration didn’t match in publish with the current build I was making, fixed that and it worked.

Thanks both of you taking and time and answer to my issue, much appreciated!

2 Likes