In the MAUI class library, within the platform-specific code, I have the following class:
public partial class Connector
{
internal partial void ReadData(string command, Action<string, string> readCallback)
{
}
internal partial void WriteData(string command, Action<string, string> readCallback);
}
Outside platforms folder I have the following class:
public partial class Connector
{
internal partial void ReadData(string command, Action<string, string> readCallback);
internal partial void WriteData(string command, Action<string, string> readCallback)
{
}
}
The provided code functions correctly when implemented in a MAUI app. However, when incorporated into a MAUI library, an issue arises: the compiler reports an error stating that the partial method "ReadData" must have an implementation, and there is no definition found for the "WriteData" method. WHY?
error:
Error CS0759 No defining declaration found for implementing declaration of partial method 'Connector.WriteData(string, Action<string, string>)'.
Error CS8795 Partial method 'Connector.ReadData(string, Action<string, string>)' must have an implementation part because it has accessibility modifiers.
Some articles recommend against employing partial methods in cross-platform libraries without mentioning the reason. Refer to the following resources for more information:
Maui class library: Partial Method issue
Before you call it an insufficient information, I recommend you create a MAUI library/App and simply copy-paste my code. It should not take a maximum of 5 minutes.
I can reproduce your problem. It was caused by the different namespace for the partial class. The official document about Implementing the API per platform said:
But when you create a class in the Platforms folder, its default namespace is
YourProjectName.Platforms.PlatformName. Please make the partial classes's namespace in the platforms folder is same as it in the share project.