xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.52k stars 505 forks source link

The type or namespace 'Platform' does not exist on iOS #2119

Closed metal450 closed 10 months ago

metal450 commented 10 months ago

Description

I'm successfully using Xamarin.Essentials in the Android project of a cross-platform Avalonia app.

From the iOS project, if I try to use FileSystem.CacheDirectory, I get Xamarin.Essentials.NotImplementedInReferenceAssemblyException: 'This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.

I'm definitely referencing Xamarin.Essentials from all 3 projects (the iOS project, the Android project, and the "common" project). I'm assuming the inability to use FileSystem.CacheDirectory is because I haven't initialized Xamarin by calling Xamarin.Essentials.Platform.Init(), per the Getting Started guide - however, I can't, as I get "The type or namespace 'Platform' does not exist in the namespace 'Xamarin.Essentials'.

I've seen other issue reports with a similar error message (i.e. https://github.com/xamarin/Essentials/issues/1964), however they relate to Android, not to iOS.

Steps to Reproduce

  1. Install Avalonia for Visual Studio 2022: https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.AvaloniaVS
  2. Create a new Avalonia Cross Platform Application
  3. Set AvaloniaApplication1.iOS as the Startup Project
  4. Add the Xamarin.Essentials nuget package to the AvaloniaApplication1.iOS project
  5. Open AppDelegate.cs, & in CustomizeAppBuilder(), try to use Xamarin.Essentials.Platform. It says it doesn't exist in Xamarin.Essentials

Basic Information

jfversluis commented 10 months ago

Looking at https://github.com/AvaloniaUI/Avalonia.Essentials you probably will have more luck with .NET MAUI Essentials rather than Xamarin.Essentials. Good luck!

metal450 commented 10 months ago

I'm already using it all over my app in the Android portion. Is there some reason why this doesn't work on iOS? That answer really has no info at all about what the issue is...it just says "use something else"...

jfversluis commented 9 months ago

@metal450 you're trying to use a product that targets Xamarin on a completely different framework that we don't support with Essentials. Additionally, this project is also set to retire in a few month.

I'm pointing out other options for you to explore where people have been successful with making this work with Avalonia and I hope that will help you. Sorry if that wasn't clear from my message.

metal450 commented 9 months ago

Additionally, this project is also set to retire in a few month.

Ah, I see. Would probably good to have a prominent note about that, would it not? So new users starting out with new projects know that support is about to be dropped & we should probably start out with alternatives instead...