2

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.

"Can not resolve reference: `System.Memory`" or "Could not find `System.Memory`" after update to Visual Studio 2017 version 15.8 Preview

Victor Chelaru
  • 4,491
  • 3
  • 35
  • 49

1 Answers1

0

I have found a workaround - by referencing System.Memory version 4.5.0 (specifically this version) in my iOS project, my project runs. I can continue to reference System.Memory 4.5.4 in my .NET Standard project, so the only change needed is in the iOS project.

Note that this means my solution is referencing mixed versions of System.Memory, which I believe is not recommended. However, in this case it is the only solution I could find to this problem.

Victor Chelaru
  • 4,491
  • 3
  • 35
  • 49