5

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?

3
  • Show me your current code and i might be able to help you !!!! Commented Oct 17, 2022 at 8:40
  • Hey, thanks! :) here is my project github.com/Cruik/MAUITest Commented Oct 17, 2022 at 11:29
  • Check the answer below :) Commented Oct 17, 2022 at 11:56

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.