views:

189

answers:

2

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 ._.

A: 

I should stress that I've not used this library before. However, looking at the stacktraces, the method that throws the exception takes a GraphicsDevice object. I'm guessing that that object comes from the GraphicDevice property of your "graphics" object. Try checking that that property contains what you expect before passing it in to the FormCollection constructor. That may help point you in the right direction.

Dan
A: 

I finally figured out what happened... It seemed that I needed some sort of config file. The library seems to be for XNA 3.0 while I was using 3.1 The config file seemed to do some sort of mapping between the two. Once I added the file, it fixed the problem. I'm still not entirely sure why though.

Kyle