This project is read-only.

ArgumentNullException on this.Content.Load<Texture2d>

Jul 1, 2011 at 10:50 AM

Hey all,

I have basically empty XNA/Silversprite game; it just has one image, ship.png (in the root of the project), which is added (I tried both as Content and Resource).

When I call this.Content.Load<Texture2D>("ship.png"), I get an ArgumentNullException:

Value cannot be null.
Parameter name: input

Any ideas?

Below is my Game class code.


Also, I have two versions of FSB, so I'm not sure if I should be using the SilverSprite classes or the XNA classes (eg. Game2D extends SilverArcade.SilverSprite.Game or Microsoft.Xna.Game).




public class Game2D : Game
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        Texture2D ship;

        public Game2D()
            graphics = new GraphicsDeviceManager(this);
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;

        protected override void Initialize()
            // TODO: Add your initialization logic here

        protected override void Update(GameTime gameTime)
            // TODO: Add your update logic here

        protected override void Draw(GameTime gameTime)

            this.spriteBatch.Draw(this.ship, new Vector2(100, 100), Color.White);


        protected override void LoadContent()
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            // TODO: use this.Content to load your game content here
            ship = this.Content.Load<Texture2D>(@"ship.png");

        protected override void UnloadContent()
            // TODO: Unload any non ContentManager content here


Jul 1, 2011 at 11:05 AM
Edited Jul 1, 2011 at 11:05 AM

Figured this out. I can't specify (for some reason?!) .png, i.e. this works:


ship = this.Content.Load<Texture2D>(@"ship.png");

This is definitely a "what the ... ?!" moment for me. Is there some reasonable explanation for this?

Jul 1, 2011 at 1:18 PM

This is probably a bug, the code expects you not to specify the file extension, we should probably check to see if it's there and act appropriately. If you renamed your file to ship.png.png this would probably work.

Jul 1, 2011 at 4:11 PM
Edited Jul 1, 2011 at 4:11 PM

@billreiss I'm surprised, because I used FlatRedBall before this, which uses SilverSprite too; I got away with specifying no extension.

C'est la vie, I suppose. I would appreciate it if you could fix this, but it's not really important, since I never have the same file with multiple extensions. But I'd really like to know if I should be using Microsoft.Xna namespaces for Game, GameTime, Sprite, etc. classes or the SilverArcade.SilverSprite namespace.