runtime: System.Text.Json: Method not found System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8 happening in Xamarin.Android

Description

After updating VS 2022 to 2.1 I am getting a System.MissingMethodException for int System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan``1<byte>) when targeting Xamarin.Android. The App builds successfully and once I use ReadFromJsonAsync<>() on my HttpResponseMessage-Content the exception in thrown. But it works with VS 2019 Version 16.10.4.

I know that there were issues for iOS and MacOs open in this repo, but I couldn’t find one for Android, so I guess, this is related to https://github.com/dotnet/runtime/issues/49211

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 30 (22 by maintainers)

Most upvoted comments

I can reproduce the issue using @codedbycurtis repo, thank you!

Actually scratch that, looks like that was a red herring. The real issue is XAML Hot Reload. If you turn off XAML Hot Reload in VS settings then it should work.

image

A new report from VS Feedback:

Sumit Gupta posted on Oct 6, 2021:

I have a Xamarin.Forms 5 App, that use Plugin.Notification (from Github) and we get error same error (randomly, not always) when compiled through VS 2022, Preview 4.1 but it works fine in VS 2019.

As suggest we do have System.Memory, 4.5.4 and System.Buffers included in projects. But that doesn’t help in Preview Edition. Surely it is compiler not linking files properly.

I do think there’s still a product concern here, my suggestion was just a workaround. @marek-safar who can check that the fixes that @filipnavara made to the Xamarin targeting packs are still working correctly in VS2022? Seems like this might important for the 6.0 release. cc @akoeplinger @steveisok