Null reference exception when running Content.RootDirectory = "Content";

Hello, I’m new to MonoGame. I’m currently working on my own little library that wraps around MonoGame, adding some utilities for myself.

Here is the code that errors. (Line 29)

Here is the code that creates the SharpContext object.

When running the game, the following error occurs:

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at SharpEngine.SharpContext..ctor() in /run/media/disk/dev/games/SharpEngine/src/SharpContext.cs:line 24
   at SharpGame.Game1..ctor() in /run/media/disk/dev/games/SharpGame/Program.cs:line 9
   at SharpGame.Program.Main(String[] args) in /run/media/disk/dev/games/SharpGame/Program.cs:line 22
Aborted (core dumped)

If any more info is needed, I’m happy to provide it.

Thanks in advance for any help :slight_smile:.

You should maybe look into not doing what you are trying to achieve, you have set out to wrap your own engine code around Monogame, well thats what you should do anyways, when you want to make a generall game, the options inside MonoDevelop are to make a generall project, which you should have done in my oppinion… since the monogame library project template is for code that you want to carry over into a plattform dependent or in the case of opengl project template a platform independent project template.

I have tried myself to create a sort of Game2 class that also extends from game and tried to get Game1 to run it, well it wouldnt, after making some more projects I guess Monogame makes a lot of things behind the scenes, like opening threads on its own. I guess the makers just want to prevent abuse from happening, so if people want to hide certain threads inside a game, well they cant because everything that runs inside that project and is part of it will be part of the main thread… that creates some pretty whacky behavior… since it is common knowledge in C# that calling the main thread wont influence other function, say as in calling Thread.Sleep() wont affect your graphics layer if you ever did something like that by hand… software side renderd games can do these things, but monogame renders its stuff hardware side, so calling sleep inside the main thread monogame opens, means stuttering will happen, I saw this with my own eyes, monogame wont allow another child of game to dominate over the main thread… but it will create other threads without you putting aditional code to do so, crazy right? As i said, i think its a security feature…

So in summary, use the normal project template, in this case the platform independent open gl project template to create your platform independent game engine, make a nice folder for all your source files that are part of the engine and make base monogame your test environment, thats also a way of making sure your engine will run for everybody, because if it will run in open gl, it can run integrate into the directx one and others as well… okay sorry for rambleing on about this… could you help me with my issue too?

thanks in advance!