The type or namespace name 'Platforms' does not exist in the namespace

AG 521 Reputation points
2023-02-16T09:44:21.9133333+00:00

Hi,

I am trying to start writing Android specific code in order to read SMS messages from the device but I am facing an error as in the Title of this question.

Repo is here https://github.com/asafgo/ReadSMSMessages

  1. adding a IMyReadSMS.cs Interface as public to root of my project.
  2. adding MyReadSMS.cs class as public inheriting from IMyReadSMS.cs to Android folder.
  3. adding using ReadSMSMessages.Platforms.Android; to MauiProgram.cs and now I am getting the mention error.
  4. at MauiProgram.cs choose ReadSMSMessages (.net7.0-android) for the platform.
namespace ReadSMSMessages
{
    public interface IMyReadSMS
    {
        Task<bool> RequestPermissions();
        Task<string[]> getAllSms();
    }
}
namespace ReadSMSMessages.Platforms.Android
{
    public class MyReadSMS : IMyReadSMS
    {
        public Task<string[]> getAllSms()
        {
            throw new NotImplementedException();
        }
 
        public Task<bool> RequestPermissions()
        {
            throw new NotImplementedException();
        }
    }
}

using ReadSMSMessages.Platforms.Android;
using Microsoft.Extensions.Logging;
 
namespace ReadSMSMessages;
 
public static class MauiProgram
{
	public static MauiApp CreateMauiApp()
	{
		var builder = MauiApp.CreateBuilder();
		builder
			.UseMauiApp<App>()
			.ConfigureFonts(fonts =>
			{
				fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
				fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
			});
 
#if DEBUG
		builder.Logging.AddDebug();
#endif
 
		return builder.Build();
	}
}

Thanks for any help,

AG

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Alessandro Caliaro 4,196 Reputation points
    2023-02-16T09:48:08.5633333+00:00

    using ReadSMSMessages.Platforms.Android;

    this is the line with the error?

    I think you should use

    #if ANDROID

    using ReadSMSMessages.Platforms.Android;

    #endif

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

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.