Aug 20, 2009 at 1:25 AM

Hi, I tried to integrate the physics engine into my existing engine, but when I add a PhysicsComponent to a GameComponentCollection object it throws the following error:

System.ArrayTypeMismatchException was unhandled
  Message="Attempted to access an element as a type incompatible with the array."
       at System.Collections.Generic.List`1.Insert(Int32 index, T item)
       at System.Collections.ObjectModel.Collection`1.InsertItem(Int32 index, T item)
       at Microsoft.Xna.Framework.GameComponentCollection.InsertItem(Int32 index, IGameComponent item)
       at System.Collections.ObjectModel.Collection`1.Add(T item)
       at TGE.MainGame..ctor() in MainGame.cs:line 217
       at TGE.Program.RunGame() in Program.cs:line 21
       at TGE.Program.Main(String[] args) in Program.cs:line 12

I'm doing just this in the constructor of my main game class:

PhysicsComponent physics = new PhysicsComponent( this, new SweepAndPruneCollisionSystem() );
Components.Add( physics ); //Error.
I don't know what to do, it seems I do everything like in the sample..? Can anyone help?

Aug 21, 2009 at 5:56 AM

Hey fl4ke,

Is it possible that your engine is compiled with a different XNA framework version?  The latest release is compiled with (and have references to) the 3.0 version of the XNA framework.  The latest source code, though, is compiled with 3.1 version. 

Hope that helps!

Aug 23, 2009 at 12:25 PM

Yes that was the problem, thanks so much for pointing to that! I thought it would automatically update 3.0 projects to 3.1 but obviously it doesn't. I'm glad it's working now.