einsteinsci
einsteinsci

Reputation: 1147

Instance Argument: Cannot convert an object to its own type

I am creating a MonoGame Project via the NuGet packages. I started with a blank project and ran "Install-Package MonoGame" in the Package Manager Console. Afterwards I copied all my old code, changed the namespace to the new project name, and since then I am having strange build issues with Visual Studio, that don't go away after restarting VS or Rebuilding the Solution.

All of them have to do with Vector2 objects. I have had to create an extension method to access Vector2.X because VS could not find a definition for X within Vector2, even though if I hit F12 it takes me straight to Vector2.X. I've had to create a static method to create Vector2 instances because "new Vector2(x, y)" is an invalid argument for a method that needs Vector2 objects as parameters. Lastly, I have this line of code:

PhysicsBody.Position = Extras.ToSimUnits(new Vector2(value.X, value.Y));

And for it I get the error "Instance Argument: cannot convert from 'Microsoft.Xna.Framework.Vector2' to 'Microsoft.Xna.Framework.Vector2'". How is this even possible? I know I can continue adding static methods to do simple things that for some reason cause build errors until all the Vector2 stupidity is gone, but is there a fix that will make this work correctly?

Upvotes: 1

Views: 459

Answers (1)

Mark Larter
Mark Larter

Reputation: 2363

MonoGame is most likely referencing a different version of XNA, or has used the same namespace for an alternate implementation to minimize code impact to end developers.

See @ayls answer to this similar question Monogame Ambiguous Vector2 for an approach.

Actually, this answer from @Andrew Russell looks even more authoritative Ambiguous reference between MonoGame & Microsoft.XNA.Framework namespaces

Upvotes: 1

Related Questions