Summary
I have a solution with two projects: a .NET Standard and an iOS project which references the .NET Standard project.
If the .NET Standard does not reference System.Memory nuget package (specifically versions 4.5.3 or 4.5.4), everything works fine. If I add a reference to System.Memory in the .NET Standard project, then my iOS project crashes with a MissingMethodException.
Note: This problem is iOS only, it does not reproduce on Xamarin Android.
How can I solve this problem?
Details
My project is using the TopTen.RichTextKit library ( https://www.nuget.org/packages/Topten.RichTextKit/ ) to perform text block measurement. When I run my code on iOS, I get the following crash when calling TextBlock.MeasuredHeight:
System.InvalidOperationException: 'Exception in BuildFontRuns() with original length of 11 now 11, style run count 1, font run count 0, direction overrides: False'
This has an inner exception:
Method not found: void SkiaSharp.SKFont.GetGlyphs(System.ReadOnlySpan`1<int>,System.Span`1<uint16>)
By removing nuget packages one-by-one and using a test project, I found that the error occurs if I reference System.Memory version 4.5.4 in my .NET Standard project. If I remove this version, the crash goes away.
Furthermore, different versions of System.Memory result in different behavior:
- 4.5.0 - works
- 4.5.1 - won't compile
- 4.5.2 - won't compile
- 4.5.3 - crashes
- 4.5.4 - crashes
Unfortunately I can't downgrade to System.Memory 4.5.0 because other libraries require version >= 4.5.4.
I don't fully understand the explanations, but I've found some links suggesting that the iOS implementation of System.Memory is not complete. For example:
This means that Xamarin projects now depend on the implementations from the NuGet package instead. And the System.Memory NuGet package version 4.5.1 accordingly does not include placeholder files for Xamarin project types.