# Game() parametters Content and Window are not pre initialized

I've been experiencing a really Strange problem since recently, Every variables of XNA Framework Game class seems not to be initialized before my extending Game1 class. Variables does not seem to be initialized before the point where they should be.

I do not plan to change the game engine, but I'll appreciate any help of any kind.

Thanks for your time

here is my Game1 class (a small part of it)

public class Game1 : Game
{
public static GraphicsDeviceManager graphics;
public static SpriteBatch spriteBatch;
public static ContentManager ContentManager;
public static SceneManager SceneManager { get; private set; }

public Game1()
{
ContentManager = Content;

graphics = new GraphicsDeviceManager(this);
ContentManager.RootDirectory = "Content";

// TODO: Add your initialization logic here
/*
*/
Window.IsBorderless = true;
IsMouseVisible = true;

}

(...) //The code continues
}


and here is the errors:

the Null pointer error on the Window variable occures when i declare a new Content manager

Edit:

It seem that there is a conflict between System.RunTime.Serialization v4 and v2 in my project

1>  Impossible de résoudre le conflit entre "System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" et "System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes". Choix arbitraire de "System.Runtime.Serialization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".

• Found this, come back after reading github.com/MonoGame/MonoGame/issues/5787. also this stackover question did not helped: stackoverflow.com/questions/16999469/… Jun 21, 2020 at 16:16
• tried to delete bin folders - did not worked, tried to build on vs17 - did not worked, i cannot try to open the solution on vcs2010 express because the project has been created on a newer version. I'll try to create a new project reimport one by one the nuget packages and copy my code Jun 21, 2020 at 17:46
• still having the problem after creating an other project and copied the code and content Jun 21, 2020 at 20:00
• Okay apparently it worked, I had an error because I moved my sprite batch declaration in the constructor but it's not supposed to be there. But yeah I'll create an answer with the method to overcome this problem Jun 21, 2020 at 20:06

Problem solved

i solved it by creating a new Monogame project and copying the code and the content folder into my new project folder. I did not copied the 'bin/', 'obj/', 'packages/', 'x86/' & 'x64/', 'Content/bin' and 'Content/obj' since they are built automatically. then I rebuilt the content pipeline. Everything works fine except a spriteFont not loading because I've voluntarily deleted it at some point. Note that if you do like me you will need to reimport libraries that you used and worked before having your problem.

conclusion I can get from my experience, Bad usage of some libraries can cause the project to break for ever. In my case, the game class was not initializing.

Hope this will help everyone in my situation.

bye

• also if somebody has a good tutorial in mind to import .ttf files with a sprite font I'll be really thankful Jun 21, 2020 at 20:14
• Regarding the ttf files, you can see if SpriteFont 2 is right for you - it can generate necessary files if you want it to. Jun 21, 2020 at 22:30
• thanks I'll take a look Jun 21, 2020 at 23:07
• For the Font problem I came up with the use of the library called SpriteFontPlus.MonoGame which is just what I needed, no need to use content importer, only ttf file, Cleary simplifying the way to import fonts. github.com/rds1983/SpriteFontPlus & nuget.org/packages/SpriteFontPlus.MonoGame Jul 29, 2020 at 22:25
• Huh, nice to know. Keep font copyrights in mind, especially if you're going to be releasing something - sometimes there's like a 100x price difference between being able to use the .ttf itself vs one sheet of rendered font at a specific size. Jul 30, 2020 at 7:55