error CS0104: 'View' is an ambiguous reference between 'Microsoft.Maui.Controls.View' and 'Android.Views.View'
— from the line you wrote, the compiler can see two types called View, and it refuses to guess.
Inside a .NET MAUI project the namespace Microsoft.Maui.Controls is imported into every file by a
global using the MAUI SDK generates for you. The moment a platform file adds using Android.Views;,
the bare word View means two things. Write Android.Views.View in full (or give it a
using alias) and the error is gone.
The error
The build log kept only the gist, so this is the compiler's line reproduced with the same two type names:
error CS0104: 'View' is an ambiguous reference between
'Microsoft.Maui.Controls.View' and 'Android.Views.View'
Why it happens
Open obj/ after a build and you will find the file the SDK writes on your behalf:
// <auto-generated/>
global using Microsoft.Maui;
global using Microsoft.Maui.Controls;
global using Microsoft.Maui.Controls.Hosting;
/* ... twenty more ... */
Every C# file in the project sees Microsoft.Maui.Controls.View without asking. Platform code under
Platforms/Android is still part of that project, so when it imports Android.Views — the
namespace of Android's widget base class — View now resolves two ways. C# has no priority rule for
two imported types with the same name; CS0104 is the only answer it has.
The AI writes Android code from Android memory, where View has meant one thing since 2008. It forgets
that it is standing inside a MAUI project that already owns the word.
The fix
// Platforms/Android/MainActivity.cs
private sealed class SystemBarsPadding : Java.Lang.Object, IOnApplyWindowInsetsListener
{
// Android.Views.View spelled out: inside a MAUI project, bare "View" is
// Microsoft.Maui.Controls.View — the compiler's first complaint on this file.
public WindowInsetsCompat OnApplyWindowInsets(Android.Views.View? v, WindowInsetsCompat? insets)
{
/* ... pad the content view with the system-bar insets ... */
}
}
If a file uses the Android type many times, an alias at the top keeps the fully-qualified noise out of every signature:
using AView = Android.Views.View;
/* ... */
public WindowInsetsCompat OnApplyWindowInsets(AView? v, WindowInsetsCompat? insets)
A file that genuinely needs both types can alias both. Do not remove the global using to "fix" this — the rest of the app depends on it.
Where it bit us
Season three, Part 2 (tag pocket-02
in the repo). The first Android screenshot showed the
app's header hidden under the status bar; the fix had to be native — an
OnApplyWindowInsetsListener in MainActivity.cs — and that very fix failed to compile on
this one word. The lesson: AI writes Android code inside MAUI and forgets MAUI owns the word View.
Expect the same collision with Color, Application and Button.
Frequently asked
- Why is View ambiguous in my .NET MAUI Android code?
- The MAUI SDK adds a global using for Microsoft.Maui.Controls to every file, which defines a View class. When a file under Platforms/Android also imports Android.Views, the bare name View matches both classes and the compiler reports CS0104.
- Should I disable the MAUI global usings to fix CS0104?
- No. The rest of the app relies on those implicit usings. Fully qualify the Android type as Android.Views.View, or add a using alias such as using AView = Android.Views.View; at the top of the file.
- What does CS0104 mean in general?
- CS0104 is the C# error for an ambiguous reference: a simple type name matches types in two or more imported namespaces. The fix is always to say which one you mean, either by qualifying the name or with a using alias.
More decoded errors in the Fixes category; the app this came from starts at From Prompt to Pocket, Part 1.