Nightmare Games
Nightmare Games

Reputation: 2435

Upgrading Monogame: The type exists in both Monogame and XNA

I've just downloaded the newest version of Monogame (3.5) and I'm suddenly getting ambiguous references with XNA. I'm not sure what version I had prior, but suffice it to say it's been a few years.

I've tried adding and removing assembly references in Visual Studio, but this only generates different errors.

Here's the exact message (one of them):

Error   12  The type 'Microsoft.Xna.Framework.Graphics.Texture2D' exists in both 'C:\Program Files (x86)\MonoGame\v3.0\Assemblies\WindowsPhone\x86\MonoGame.Framework.dll' and 'C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.Graphics.dll'  c:\nightmare games\games\in production\boxland incorporated\boxland (monogame)\boxland\character_control.cs 55

I'm getting these for the following types:

UPDATE:

I've attempted to remove XNA from the project, using only Monogame. Removing the assembly references and "using" statements results a multitude of "type or namespace not found" errors for the following types:

I already have the assembly reference to MonoGame.Framework. Adding new using statements for MonoGame only resulted in the error:

Error   4   The type or namespace name 'MonoGame' could not be found (are you missing a using directive or an assembly reference?)  C:\Nightmare Games\Games\In Production\Boxland Incorporated\Boxland (monogame)\Boxland\Particle_Effects.cs  5

UPDATE:

Project -> Properties -> Target Framework Changing this from ".NET Framework 4" to ".NET Framework 4.5" seems to fix the problem with Microsoft.XNA not being recognized, but this only generated new errors.

Error   2   The type or namespace name 'Graphics' does not exist in the namespace 'Microsoft.Xna.Framework' (are you missing an assembly reference?)    C:\Nightmare Games\Games\In Production\Boxland Incorporated\Boxland (monogame)\Boxland\Draw.cs  4

I'm now getting this for everything under the Microsoft.Xna.Framework umbrella, including Graphics, Input, Audio, Content, GamerServices, and so on.

Upvotes: 2

Views: 2124

Answers (2)

Nightmare Games
Nightmare Games

Reputation: 2435

Everything works now (almost). Unfortunately, this was not a quick fix. Here's a list of everything I did to get this working:

Project -> Properties -> Target Framework:

This must be set to ".NET Framework 4.5". I believe mine was 4.0 previously.

Using Statements

Keep all the "using Microsoft.Xna.Framework" statements. However, "Microsoft.Xna.Framework.GamerServices" has to go. This one is apparently no longer supported (and I'm not sure what I was using it for any longer). Trying to add "Microsoft.Xna.Framework" back in is also a bad idea.

I had the wrong assembly reference to Monogame.

This one is tricky, because the reference manager shows 14 of them, none of which say more than just "MonoGame.Framework" with a version number. Apparently they are not all the same. Hovering over the name shows different file paths. I still don't know what the difference is between Windows, Windows8, and WindowsUniversal, but the one I actually needed was not even being listed in the search results. I had to browse to the actual file, which for regular windows desktop was under: C:\Program Files (x86)\MonoGame\v3.0\Assemblies\Windows\MonoGame.Framework.dll

FileMode.Open no longer works.

This is part of System.IO, which seems to now be causing a conflict with Monogame. The solution is to use "Content.Load", which is how XNA used to do it.

I was using FileMode.Open to load Texture2D's, since old Monogame didn't support compiling content. Ironically, finding out that this is now supported was my main reason for upgrading, but I didn't think I'd be converting almost 400 sprites to the new format all in one shot. They all need to be loaded into the new pipeline tool and compiled, added to the VS project, and then the actual loading code has to change.

Switching back to Content.Load invalidated some of the classes I'd written during the interim, since Monogame doesn't seem to appreciate trying to use the GraphicsDevice from outside the main game class. These had to be heavily refactored as well.

Upvotes: 5

Petri Laarne
Petri Laarne

Reputation: 421

Your project and all referenced assemblies should only reference MonoGame. MonoGame is a full replacement for XNA and implements almost all XNA 4.0 types. The two may not coexist in a single application.

Upvotes: 0

Related Questions