# System.PlatformNotSupportedException: Operation is not supported on this platform. (Android)

- **ID:** `dotnet/maui-platform-not-supported-android`
- **Domain:** dotnet
- **Category:** platform_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

A .NET MAUI or Xamarin.Forms app is calling an API that is not available on the Android platform, such as Windows-specific filesystem APIs or iOS-only frameworks, without proper platform checks.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| .NET MAUI 6.0 | active | — | — |
| .NET MAUI 7.0 | active | — | — |
| .NET MAUI 8.0 | active | — | — |
| Xamarin.Android 12.0 | active | — | — |
| Xamarin.Android 13.0 | active | — | — |

## Workarounds

1. **Use conditional compilation with platform-specific implementations. Example: #if ANDROID // Android-specific code using Android.Content.Intent #elif IOS // iOS-specific code using UIKit.UIApplication #endif** (85% success)
   ```
   Use conditional compilation with platform-specific implementations. Example: #if ANDROID // Android-specific code using Android.Content.Intent #elif IOS // iOS-specific code using UIKit.UIApplication #endif
   ```
2. **Use the DeviceInfo.Platform property from Xamarin.Essentials or MAUI Essentials to check at runtime: if (DeviceInfo.Platform == DevicePlatform.Android) { /* Android code */ } else { /* fallback */ }** (90% success)
   ```
   Use the DeviceInfo.Platform property from Xamarin.Essentials or MAUI Essentials to check at runtime: if (DeviceInfo.Platform == DevicePlatform.Android) { /* Android code */ } else { /* fallback */ }
   ```
3. **Use dependency injection with platform-specific services. Register an interface in the shared project and implement it in each platform project. Example: services.AddSingleton<IFileService, AndroidFileService>();** (95% success)
   ```
   Use dependency injection with platform-specific services. Register an interface in the shared project and implement it in each platform project. Example: services.AddSingleton<IFileService, AndroidFileService>();
   ```

## Dead Ends

- **Adding a try-catch around the call and ignoring the exception.** — This suppresses the error but does not provide the intended functionality; it may lead to silent data loss or incorrect behavior. (90% fail)
- **Using conditional compilation (#if ANDROID) without implementing an alternative for Android.** — If the alternative is not implemented, the code will not execute at all, leaving functionality missing. (80% fail)
- **Downgrading the target framework to an older version that supports the API.** — The API is platform-specific; downgrading does not change the underlying OS capabilities. (100% fail)
