Ambiguous reference between MonoGame and Microsoft.XNA.Framework namespaces

MonoGame (the infrastructure that mainly brings XNA to Windows Phone 8) has all namespaces prefixed with Microsoft.Xna.Framework I believe to minimize the number of code changes required when porting your XNA application to MonoGame.

My problem is that I want to access the Microphone class, which, since it has not yet been created in MonoGame, I have to use it internally in the official Microsoft XNA class, for this I need to exclude the explicit forced removal of the standard Microsoft.XNA.Framework.dll The links in .csproj that my MonoGame template has a setting to avoid conflicts, which works fine, and now Microphone is available, but at the same time I created an ambiguity between several key classes that exist in Microsoft standard version and MonoGame.

I get the following errors:

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

This obviously happened because along with the standard XNA library released by Microsoft, I have a link to MonoGame.Framework.dll , which manages the namespace, creating this ambiguity. However, in all cases, I want to access the version of MonoGame.

Any ideas on 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 using Color = Microsoft.Xna.Framework will obviously not work, because both of them are marked the same way in compiled dlls!

+6
source share
1 answer

A way to solve this particular problem is to use extern alias ( MSDN , tutorial ).

Thus, you can use the Microsoft XNA DLL and specify the corresponding using statement only for the Microphone class. Continue to use MonoGame as usual.

Perhaps the best solution would be to create your own Microphone wrapper class in the Microsoft.Xna.Framework.Audio namespace using this technique. Put it in a separate assembly so you don't have to contaminate your main source code with extern alias materials.

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

(Of course, this answer says nothing about how successful you could mix MonoGame and XNA in this way, functionally. I hope it works.)

+8
source

All Articles