Xamarin Android Quickstart fails with "namespace 'Content' not found"

Tim Reynolds 111 Reputation points
2020-12-16T16:08:44.923+00:00

Trying to build a Sample / Quick Android app for Xamarin.
When it tries to build, I get an error in my MainActivity
"The type or namespace name 'Content' does not exist in the namespace 'MY NAME SPACE' are you missing an assembly reference?"
pointing to:
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)

This is the default app, prior to me making ANY changes to it.

These are the steps I have tried.

  • https://learn.microsoft.com/en-us/xamarin/get-started/first-app/?pivots=windows
  • After that failed, i did this
  • Totally uninstalled everything that "Tools>Android>Android SDK Manager" said was intalled.
  • I deleted my project folder
  • I rebooted my laptop
  • I created a new Xamarin Android project in VS
  • It failed, stating that I did not have aapt installed
  • I followed all of the guidance which suggested running an android.bat file - this failed saying it was obsolete
  • I manually installed the SDK and appropriate tools (see final versions below)
  • I still get the same errors.

INSTALLED ENVRIONMENT

Visual Studio 2019 v 16.8.3
Xamarin v 16.8.000.260
Xamarin.Android SDK v 11.1.0.17
Android SDK Platform 28 and 29
Android Platform Tools 30.0.4
Android SDK Build Tools 29.0.2
Android Emulator 30.0.6
Android SDK Tools 26.1.1
SDK Patch Applier v4

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,366 questions
0 comments No comments
{count} votes

Accepted answer
  1. Tim Reynolds 111 Reputation points
    2020-12-16T16:24:06.563+00:00

    The issue was that my project namespace was Company.Prototype.Android and something was getting confused trying to find Android.Content.PM.Permissions. I changed my namespace to Company.Prototype.PhoneApp and it now compiles.

    3 people found this answer helpful.
    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Charles Winters 6 Reputation points
    2022-05-15T11:09:41.437+00:00

    I found there is a similar problem with ApplicationName.Mobile. I'm thinking MS's example should have a fully qualified namespace to avoid all of this.

    1 person found this answer helpful.
    0 comments No comments

  2. Siamak Shamaee 5 Reputation points
    2023-03-08T21:41:26.2633333+00:00

    It's a bit funny. I got the same error because I called my solution Xamarin.Exercise.
    Once I changed it to Exercise only it started to work

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.