Error: The type or namespace name 'Interface' does not exist in the namespace (are you missing an assembly reference)

Shashank Sharma 1 Reputation point
2022-03-06T15:21:13.217+00:00

I am developing an application using Xamarin and got stuck into this error. The error has been generated from my .Droid project while building the solution (Clean Solution is successful). The 'Interface' is a folder which is present inside my Portable PCL project. Basically I want to implement an interface (declared inside my Portable project) into my .Droid project. I have already tried to refer that Interface folder with using keyword but it says does not exist. And since the folder is not getting referenced, all the interfaces inside that folder are also not getting referenced.

The below code is of .Droid project file in which interface has to be implemented.

using ProjectName;
using ProjectName.Interface;
using Xamarin.Forms;

[assembly: Dependency(typeof(FileName))]
namespace ProjectName.Droid
{
    class FileName : InterfaceName
    {
        ....
    }
}

The below code is of one of the Portable project interface file inside Interface folder.

using System;
using ProjectName;

namespace ProjectName.Interface
{
     public interface InterfaceName
     {
          ....
     }
}

When I try to Add Reference of Portable project into .Droid project it says:

Unable to add reference to Portable project. The current project's target is not one of or compatible with the targets of Portable Project.

Please Note:

  1. I am using Visual Studio 2019.
  2. My Portable project Target Frameworks are: .NET Framework 4.5, ASP.NET Core 1.0, Windows 8, Windows 8.1, Windows Phone Silverlight 8.
  3. My Droid project Target is Android 11.0(API Level 30 -R)
  4. I have already added Mono.Android.dll file inside Portable as well as Droid project.
  5. I have tried deleting bin and obj folder of both projects but didn't worked at all.
  6. I am unable to add Reference of my Portable project into my Droid project.
  7. Also, all the interfaces inside 'Interface' folder are public.

Any kind of help will be appreciated.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,362 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,005 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Ken Tucker 5,856 Reputation points
    2022-03-06T16:09:50.56+00:00

    I do not see Xamarin.IOS and Xamarin.Android in the Targeted frameworks you say are selected. Keep in mind portable class libraries are no longer supported. If possible I would switch to .net standard instead.

    https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-1-0


  2. Shashank Sharma 1 Reputation point
    2022-03-08T12:11:06.893+00:00

    I have solved this problem by myself. I have edited ProjectName.Droid.csproj file and manually inserted reference code for my Portable Project. No need to convert into .net standard at all. No need to include Xamarin.Android/Xamarin.IOS in targets. All errors are gone. Thank You everyone who contributed. Cheers.

    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.