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.
internal, they're not visible outside of the assembly they're defined in: learn.microsoft.com/dotnet/csharp/language-reference/keywords/… Also, the different parts of the class cannot be in different assemblies, AFAIK.