Odd "Object reference not set to an instance of an object" involving xWinForms
        Posted  
        
            by Kyle
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Kyle
        
        
        
        Published on 2010-04-05T01:12:55Z
        Indexed on 
            2010/04/05
            1:23 UTC
        
        
        Read the original article
        Hit count: 475
        
Hey, I've been trying to get the xWinForms 3.0 library (a library with forms support in xna) working with my C# XNA Game project but I keep getting the same problem. I add the reference to my project, put in the using statement, declare a formCollection variable and then I try to initialize it.
whenever I run the project I get stopped on this line: formCollection = new FormCollection(this.Window, Services, ref graphics);
it gives me the error:
" System.NullReferenceException was unhandled Message="Object reference not set to an instance of an object." Source="Microsoft.Xna.Framework" StackTrace: at Microsoft.Xna.Framework.Graphics.VertexShader..ctor(GraphicsDevice graphicsDevice, Byte[] shaderCode) at Microsoft.Xna.Framework.Graphics.SpriteBatch.ConstructPlatformData() at Microsoft.Xna.Framework.Graphics.SpriteBatch..ctor(GraphicsDevice graphicsDevice) at xWinFormsLib.FormCollection..ctor(GameWindow window, IServiceProvider services, GraphicsDeviceManager& graphics) at GameSolution.Game2.LoadContent() in C:\Users\Owner\Documents\School\Year 3\Winter\Soen 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Game2.cs:line 45 at Microsoft.Xna.Framework.Game.Initialize() at GameSolution.Game2.Initialize() in C:\Users\Owner\Documents\School\Year 3\Winter\Soen 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Game2.cs:line 37 at Microsoft.Xna.Framework.Game.Run() at GameSolution.Program.Main(String[] args) in C:\Users\Owner\Documents\School\Year 3\Winter\Soen 390\TeamWTF_3\SourceCode\GameSolution\GameSolution\Program.cs:line 14 InnerException: "
In a project I downloaded that used the xWinForms, I put the following code in and it compiled and ran no error. but when I put it in my project I get the error. Am I making some stupid mistake about including dlls or something? I've been at this for hours and I can't seem to find anything that would cause this.
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Xna.Framework; 
using Microsoft.Xna.Framework.Audio; 
using Microsoft.Xna.Framework.Content; 
using Microsoft.Xna.Framework.GamerServices; 
using Microsoft.Xna.Framework.Graphics; 
using Microsoft.Xna.Framework.Input; 
using Microsoft.Xna.Framework.Media; 
using Microsoft.Xna.Framework.Net; 
using Microsoft.Xna.Framework.Storage; 
using xWinFormsLib; 
namespace GameSolution 
{ 
    public class Game2 : Microsoft.Xna.Framework.Game 
    { 
        GraphicsDeviceManager graphics; 
        SpriteBatch spriteBatch; 
        FormCollection formCollection; 
        public Game2() 
        { 
            graphics = new GraphicsDeviceManager(this); 
            Content.RootDirectory = "Content"; 
        } 
        protected override void Initialize() 
        { 
            // TODO: Add your initialization logic here 
            base.Initialize(); 
        } 
        protected override void LoadContent() 
        { 
            // Create a new SpriteBatch, which can be used to draw textures. 
            spriteBatch = new SpriteBatch(GraphicsDevice); 
            formCollection = new FormCollection(this.Window, Services, ref graphics); 
        } 
        protected override void Update(GameTime gameTime) 
        { 
            base.Update(gameTime); 
        } 
        protected override void Draw(GameTime gameTime) 
        { 
            base.Draw(gameTime); 
        } 
    } 
} 
Any help would be greatly appreciated ._.
© Stack Overflow or respective owner