maui-samples
maui-samples copied to clipboard
InvokePlatformCodeDemos fails to find partial method implementations when DeviceOrientationService moved to a new Maui project
I am trying to implement partial classes for cross platform access, and although this demo works out of the box, as soon as I move DeviceOrientationService and the platform implementations into a new Maui library project, the compile complains:
/Users/dfgdfggdf/Projects/maui-samples/6.0/PlatformIntegration/InvokePlatformCodeDemos/Demo1/Services/DeviceOrientationService.cs(42,42): Error CS8795: Partial method 'DeviceOrientationService.GetOrientation()' must have an implementation part because it has accessibility modifiers. (CS8795) (Demo1)
I can't see anything different in the .csproj (other than the app config) so am at a loss as to the cause of this.
Any suggestions? Trying to implement this in a real world scenario where not all code is in a single project.
Also trying to reduce code duplication where most of our Mac and iOS code would be identical, but haven't got this basic change working yet to even try that.
@davidbritch any ideas?
I had the same problem and found the solution here.
The fix is to edit your csproj and remove any TargetFrameworks that you aren't using (note that each <TargetFrameworks> can contain multiple platforms.)
Then, make sure you've implemented your partial service on all the platforms that are remaining.
I think a nice change to Maui would be if the .csproj TargetFrameworks are added / removed as the Platforms folders are deleted / added. It would prevent this confusion. It may be easier to just make the error message a bit clearer though.
Thanks Brad, I found a similar answer elsewhere too, so my solution was to remove net6.0 from the target frameworks. All the others are implemented.
However, My Maui library projects reference a number of pure .net6 library projects, so when opening the solution the nuget restore fails. Reverting the target frameworks to include net6.0, run a nuget restore, then removing again allows me to build. Far from ideal and won't work when we get round to CICD pipelines.