CS0234: The type or namespace name 'Xna' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

I’ve had this error multiple times with Monogame over the years with different versions.

The only solution I have at the moment is to make a new project and copy the code over.

I have no idea why it happens or how to fix it without starting again from scratch.

Any help would be appreciated.

EDIT: Fixed it. :slight_smile:

Solution for Monogame 3.8:

Issue is with the Monogame.Content.Builder.Task package.

Uninstalling and reinstalling that package should help. (If not, then uninstall/reinstall all packages)

I have the same problem but the solution mentioned here does not work for me. Has anyone had an alternative solution? To give more detail, I am new to this framework. I downloaded and installed the latest version of Monogame via Visual Studio. I followed the instructions in the Getting Started documentation on this website and I got the error. I (probably wrongly) attempted to install XNA on its own but after doing so it did not appear in the reference manager.

When I installed Visual Studio 2019 and MG 3.8, I also followed the Getting Started documentation. From what I remember, I didn’t get any errors, so I’m not sure what went wrong for you there.

My issues with this error in 3.8 seem to be isolated to individual projects, so creating a new project, or uninstalling/reinstalling nuget packages does the trick.

If you are having issues from the get go with all MG 3.8 projects…

  1. Make sure you are using VS 2019.
  2. Make sure you’ve installed the Monogame extension, mgcb editor etc.

There’s not need to install XNA seperately, so that may be causing the issue.

Other than uninstall/reinstall, there isn’t much I can suggest.

In my case the problem was apparently with my Windows username, which had a space in it. Someone in the Discord mentioned that this was a bug with the stable version. So instead I installed the development version at Install a development MonoGame build - Learn MonoGame which works for me.

Yes this was my case as well. The solution is:

Open the MonoGame.Content.Builder.Task.targets file at C:\Users\User Name\.nuget\packages\monogame.content.builder.task\\build

and Modify the Target with “RunContentBuilder” name.

Simply add " before and after $(MGCBPath) in the Command.

Should read: Command="$(DotnetCommand) "$(MGCBPath)" $(MonoGameMGCBAdditionalArguments).....