The error message you gave said that imageName was null, so double check what you are sending it when constructing the TexturePrimitive object. Can you provide a snippet of the code you use that constructs the TexturePrimitive object?
It is just a typo mistake, or else the compiler would have marked this as an error while building: "Error 13 ‘xyz’ does not contain a definition for ‘abcd’ and no extension method ‘abcd’ accepting a first argument of type…
whereas Object reference is a runtime error.
It is likely imageName is null, or Game1 as we don’t see how this one is initialized.
I’m guessing that imageName is null, but the OP said it has a value, so I was wondering if sContent was a typo or it could actually be an object (maybe a “static field” on Game1 that is null since Game1 is an actual class name (in a new project) and not an instance of the class and doesn’t contain “Content”. My theory is he’s created a static field to contain the “content” so he doesn’t have to store a reference to the class or pass it around.
but since he mentioned:
imageName:Object reference not set to an instance of an object.
Usually the incriminated line is pointed, not the variable. And has visual places the popup almost at the end…
“Additionnal Information: Object reference not set to an instance of an object.”
Until we get the chance to know the whole stacktrace and the watches, we can only do assumption
Without any further information, all we can suggest is to use the debugger, find out which variable is null and follow it back up the callstack to see where it is coming from.
Harag what you said is right,i did created a static field as you all can see here:
(part of the Game1 class):
static public SpriteBatch sSpriteBatch;
static public GraphicsDeviceManager sGraphics;
static public ContentManager sContent;
const int kNumObjects = 4;
//TP Class
TexturedPrimitive[] mGraphicsObject;
int mCurrentIndex = 0;
The Monogame tutorial is the latest one (and a weekly series), but he’s done some older ones in XNA - which you could still do but would need to tweak as you go along - e.g. the content pipeline is quite different to how it was in XNA, but the code should be basically the same.
Couple more links in case you’ve not found them, which I found really good.