I'm trying to implement plattform specific partial method in .NET MAUI to get the connection string for the database.
In the "main application":
namespace TestApp.DL;
public partial class BaseHandler
{
public partial string GetDBPath();
private string GetCnnPath()
{
var dbPath = GetDBPath();
var cnnPath = $"Data Source={dbPath}";
return cnnPath;
}
...
}
in the platform folders in the project:
where each contain the plattform specific implementation:
namespace TestApp.DL;
// All the code in this file is only included on Android.
public partial class BaseHandler
{
public string GetDBPath()
{
var dbName = "com.mycompany.mydatabase.db";
return Android.App.Application.Context.GetDatabasePath(dbName).AbsolutePath;
}
}
...but I keep getting "Error CS8795: Partial method 'BaseHandler.GetDBPath()' must have an implementation part because it has accessibility modifiers. (CS8795)". It seems like the platform specific files are not seen by the compiler? Note, they are in a separate assembly project from the main application but that should be ok I guess, given that the fwk created the folders for me?

First of all, your implementation must use the partial keyword as well:
Then, you should make sure that you're following the guidelines for multi-targeting: https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/configure-multi-targeting#configure-folder-based-multi-targeting
You'll need to update your .csproj file with the following:
Without this, you would see another compiler error because you can only provide one body for any partial method declaration. You need to provide platform specific implementations for each platform and disable the compilation of the ones that are not needed or you can add a default implementation, but then you need file-based multi-targeting instead of platform-based multi-targeting (or a combination of both).
I've had a similar problem already and solved it here: MAUI: How to use partial classes for platform specific implementations together with net7.0 as TargetFramework in the SingleProject?