Search code examples
c#rider.net-maui

Problem with platform specific code in .NET MAUI and Jetbrains Rider


i am having the following problem. i try to invoke platform specific code in the .NET MAUI from the microsoft tutorial. https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/invoke-platform-code

The problem here is that it can be compiled and builded with Visual Studio, but with Rider from Jetbrains it cant be compiled. i m getting the following error message:

DeviceOrientationService.cs(5, 38): [CS8795] Partial method 'DeviceOrientationService.GetOrientation()' must have an implementation part because it has accessibility modifiers.

Anyone got an idea what i am missing?


Solution

  • So the thing is you need to create an implementation for your abstract method on all platform classes for it to be able to build since you are targeting multiple platforms.

    So just like you have an implementation in your Android and iOS platforms you need it on others as well.

    There is another way as well which is you can create an abstract method with an implementation that already does something on other platforms so assume this method is only relevant on Android and iOS then you would do something like below in this class:

    public partial class DeviceOrientationService
    {
     #if ANDROID || IOS
        public partial DeviceOrientation GetOrientation();
     #else
        public partial DeviceOrientation GetOrientation()
        {
             return DeviceOrientation.Undefiend;
        }
     #endif
    }
    

    Also if you don't want to support Tizen, Windows or MacCatalyst you can just remove their references from the csproj file and then you can delete their platform folders and you won't need to do the above-mentioned things at all your app will only expect Android and iOS code for the above project.