Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous reference between MonoGame & Microsoft.XNA.Framework namespaces

MonoGame (a framework which basically brings XNA to Windows Phone 8) has all it's namespaces prefixed with Microsoft.Xna.Framework I believe to minimise the amount of code changes required when porting your XNA app to MonoGame.

My issue is, I wish to access the Microphone class, which, because has not been created in MonoGame yet, I have to utilize it from within in the official Microsoft XNA class, this requires taking out the explicit forced removal of the standard Microsoft.XNA.Framework.dll references within the .csproj that my MonoGame template has setup to avoid conflicts, which works great and now Microphone is accessible, but in doing so I have created ambiguity between a few key classes which both exist in Microsoft standard issue and MonoGame.

The errors I am receiving are:

Ambiguous reference:
Microsoft.Xna.Framework.Color
Microsoft.Xna.Framework.Color

This has obviously occurred because alongside the standard Microsoft-issued XNA library, I have a reference to MonoGame.Framework.dll which commandeers the namespace, creating this ambiguity. However, in all instances, I wish to access the MonoGame version.

Any ideas how I can explicitly tell the compiler to use the MonoGame version of the Color and Vector2 class and not the official Microsoft one?

Any attempt in a using Color = Microsoft.Xna.Framework obviously won't work because they are both labelled the same in the compiled dlls!

like image 256
GONeale Avatar asked Mar 05 '13 13:03

GONeale


1 Answers

The way to solve this specific problem is by using an extern alias (MSDN, tutorial).

That way you can alias the Microsoft XNA DLL and specify an appropriate using statement just for the Microphone class. Continue using MonoGame as normal.

Possibly a better solution might be to make your own wrapper class called Microphone in the namespace Microsoft.Xna.Framework.Audio using this technique. Put it in a separate assembly so you don't have to pollute your main source code with the extern alias stuff.

The ideal way, of course, is to actually implement Microphone for MonoGame and contribute it ;)

(Of course, this answer says nothing about how successful you might be at mixing MonoGame and XNA in this way, functionality-wise. Hopefully it works.)

like image 146
Andrew Russell Avatar answered Sep 30 '22 17:09

Andrew Russell