Joe Morano
Joe Morano

Reputation: 1895

Shared Xamarin.Forms - The type or namespace name 'App' does not exist in the namespace

I'm making my way through this Xamarin.Forms tutorial. I built a Shared project according to the instructions, but I'm getting an error on a file that I was given to download, that is supposed to let my app access the dialing function on Android.

This is the full error I'm getting:

CS0234  The type or namespace name 'App' does not exist in the namespace 'Phoneword.Android' (are you missing an assembly reference?)   Phoneword.Android

I found a few similar-sounding errors online, including this one, but none of the solutions worked for me. The general trend seemed to be that the App class lives in the Shared project, so a broken reference might be causing the problem, but I removed the Android reference to the Shared project, and a bunch of other errors came up, and then I re-added it, and all the errors but the "App" one went away. So I don't think it's a reference issue.

PhoneDialer.Droid.cs (I marked the line with the error)

using Android.Content;
using System.Linq;
using System.Threading.Tasks;
using Android.Telephony;
using Xamarin.Forms;
using Phoneword.Android;

using Uri = Android.Net.Uri;
[assembly: Dependency(typeof(PhoneDialer))]

namespace Phoneword.Android
{
    public class PhoneDialer : IDialer
    {
        public Task<bool> DialAsync(string number)
        {
            var context = Android.App.Application.Context; //<=ERROR
            ...
        }
        ...
    }
}

When I change the line to Phoneword.App.Application.Context, "App" doesn't throw any error, but then I get another error saying that "Application" doesn't exist.

Anyone have any idea what the problem could be?

I uploaded the solution to github so all my code is visible: https://github.com/joeymorano/Phoneword

Upvotes: 3

Views: 1349

Answers (1)

Shiwanka Chathuranga
Shiwanka Chathuranga

Reputation: 889

Cheeky Error....

Change your current namespace namespace Phoneword.Android to namespace Phoneword.Droid, everything will work

When you have namespace called namespace Phoneword.Android and try to access Android.App.Application.Context, Android. refer as your current project... not the android native library

enter image description here

Upvotes: 4

Related Questions