This project is read-only.

Adding xna to WP7 references

Dec 3, 2012 at 2:27 AM
Edited Dec 3, 2012 at 2:06 PM

This is a very basic question as I am new to this and sure i am missing something simple. 

Here are my steps at new project.

I add reference to the spriter.farseerhelper and farseerphysicsenginewp7

i create a couple sprites in xaml mainpage.

i'll add a button and the applyforce method from one of the sprites.

At this point i need add a reference to xna framework as to pass the Vector2 datatype required for applyforce.  If i run it works great, however if I then go into Blend make any changes, and then reload back in studio it no longer works with the error Cannot create an instance of "PhysicsSprite". Most of the xaml has is squiggled with that error.

If i remove ref. to xna and the comment the code in code behind it rebuilds with now errors.

Any ideas? This is just a single mainpage example but I cannot seem to get around it.

also the error associated with the xaml error is

at Microsoft.Xna.Framework.Vector2.get_Zero() at Spritehand.FarseerHelper.PhysicsSprite..ctor() in C:\dev\physicshelperxaml\Spritehand.PhysicsHelper.Metro\PhysicsSprite.cs:line 844


Common Language Runtime detected an invalid program.

Dec 4, 2012 at 4:37 AM

If i follow your the documentation exactly , but then add xna framework it errors out similiar to above. Without the framework added how to i use the Vector2 datatype. It seems to be interefing with the framework reference in physicssprite.cs but i am not sure why.

This makes it impossible to use applyforce to any of the samples for WP7 since it requires the added reference to Xna to access the Vector2 datatype.

Any direction would be appreciated.

Dec 7, 2012 at 11:38 AM

It sounds like Blend is doing something to the reference? If you do not go into Blend then it is OK?

I have a WP7 project that is referencing Xna OK in the project (v4.0.30319), and if the Physics Helper also references Xna (v4.0.30319).

If you expand the References in your projects in Solution Explorer, is the Path for Xna something like:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0\Profile\WindowsPhone71\Microsoft.Xna.Framework.dll

(note the 71) - could it be that you have a version of Blend that is older and doesn't support 71?

Dec 7, 2012 at 1:23 PM

Thanks for the reply,

The issue ended up not even being related to Blend.  All i had to do was reference xna , add a physicssprite object and build. The xaml designer was unable to draw the sprite at that point. with the error Cannot create an instance of "PhysicsSprite". If i removed ref to xna it worked fine. This seem to be only a designer issue too because i could still deploy and see the sprites, just not thru the xaml designer??

I checked xna paths - versions, etc. It always would break and reference the on line 844

After hours and hours of banging my head I was able make it work by modifiying your physicsprite.cs code

specifically line 844-ish

private xna.Vector2 _position = Vector2.Zero;

I changed it to just

private xna.Vector2 _position;

After that everything worked fine , I've used applyforce etc without the issue. Incidently i was never able to find another example of .Zero being called outside of a sub routine in any other part of your code or farseer classes. With very little knowledge of the rules surrounding Vector2 that was what i came up with.

Can you tell me why this worked and if that is a bug or indicative of another issue?