Ambiguous reference between MonoGame & Microsoft.XNA.Framework namespaces

杀马特。学长 韩版系。学妹 提交于 2019-12-07 03:32:35

问题


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!


回答1:


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.)



来源:https://stackoverflow.com/questions/15225017/ambiguous-reference-between-monogame-microsoft-xna-framework-namespaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!