0

I have an error that just came up since Apple released iOS 15. I had a method in my Xamarin.iOS project that was successfully parsing a file using Json, and it broke. I wanted to check and see if anyone else has observed this same problem, and has a suggestion. Google searches didn't turn up any result of folks talking about it, and searching here on SO for the terms "JSON", "iOS", and "15" turned up 6 tickets that had nothing to do with my question. Thanks for any help you can offer. (I'm not sure which tags to apply to this question, so I picked some. If you want to adjust them, feel free.)

private void AddPhotoMetadatasToJsonFile(List<PhotoMetadata> metadatas)
{
    var existingMetadatas = GetLocalPhotoList();

    if (existingMetadatas.Count > 0)
    {
        metadatas.AddRange(existingMetadatas);
    }

    var json = JsonSerializer.Serialize(metadatas); //This line throws the exception
    File.WriteAllText(MetadataFile, json);
}

Exception:

Method not found: int System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan`1<byte>)
[0:]   at System.Text.Json.JsonEncodedText.EncodeHelper (System.ReadOnlySpan`1[T] utf8Value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00000] in <cb68364b029e41c3bf425990b94c94d9>:0 
  at System.Text.Json.JsonEncodedText.TranscodeAndEncode (System.ReadOnlySpan`1[T] value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00033] in <cb68364b029e41c3bf425990b94c94d9>:0 
  at System.Text.Json.JsonEncodedText.Encode (System.ReadOnlySpan`1[T] value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00014] in <cb68364b029e41c3bf425990b94c94d9>:0 
  at System.Text.Json.JsonEncodedText.Encode (System.String value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00014] in <cb68364b029e41c3bf425990b94c94d9>:0 
  at System.Text.Json.JsonSerializer..cctor () [0x00042] in <cb68364b029e41c3bf425990b94c94d9>:0 
Nate W
  • 275
  • 2
  • 13

1 Answers1

0

I think I figured out a temporary solution based on this support ticket. It looks like using System.Text.Json doesn't compile correctly, but adding the NuGet package Newtonsoft works correctly. Here's my revised code:

using Newtonsoft.Json;

private void AddPhotoMetadatasToJsonFile(List<PhotoMetadata> metadatas)
{
    var existingMetadatas = GetLocalPhotoList();

    if (existingMetadatas.Count > 0)
    {
        metadatas.AddRange(existingMetadatas);
    }

    using (StreamWriter sw = new StreamWriter(MetadataFile))
    {
        var serializer = new JsonSerializer();
        serializer.Serialize(sw, metadatas);
    }
}
Nate W
  • 275
  • 2
  • 13