Why can't I resolve ambiguity with Android.OS.Environment?

Posted by C. Lang on Stack Overflow See other posts from Stack Overflow or by C. Lang
Published on 2013-07-01T06:24:32Z Indexed on 2013/07/01 23:05 UTC
Read the original article Hit count: 1268

Filed under:

I'm trying to use Environment.(...) in my Xamarin app. It complains that

"Environment is an ambiguous reference between System.Environment and Android.OS.Environment"

I can fix it by using the fully qualified name System.Environment.(...) but not with Android.OS.Environment.(...).

For example:

// Obviously ambiguous with error above
using System;
using Android.OS;

// ...
// OnCreate uses Bundle also in Android.OS 
//...

string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
// Can be fixed by prefixing Environment with "System."

But I can't fix it with any variation of possibilities using Android.OS including removing it and explicitly using it. The auto-complete box only shows the Activities and "Resource" and not any of the classes.


// Solution to be able to use Android's Environment
using Android.OS;

// same as above

Java.IO.File storageDir = Environment.ExternalStorageDirectory;
// Defaults to Android.OS but can still use "System.Environment.(...)
// Of course not with this example, but with the one above; yes.
// Why doesn't it work both ways? If I remove the using statement and 
//     try to use Android.OS.Environment.(...) it complains
// 'OS type or namespace doesn't not exist'

The reason is prefixing with Android. is referring to MyAppName.App.Android.


Why is that and is there a way to directly access Android.OS.(...)?
I've tried Mono.Android.OS.(...).

© Stack Overflow or respective owner

Related posts about monodroid