Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Text.Json.JsonSerializer' threw an exception. ---> System.MissingMethodException #10839

Closed
eltra-ch opened this issue Mar 11, 2021 · 4 comments

Comments

@eltra-ch
Copy link

just updated to visual studio 16.9.1, Visual Studio for Mac 8.9 (build 1651). Latest Xamarin Forms 5.0.0.2012 etc.

by calling Serialize using System.Text.Json.Serializer of simple class (UserIdentity) below:

I get following exception:

System.TypeInitializationException: The type initializer for 'System.Text.Json.JsonSerializer' threw an exception. ---> System.MissingMethodException: Method not found: int System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan1<byte>) at System.Text.Json.JsonEncodedText.EncodeHelper (System.ReadOnlySpan1[T] utf8Value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00000] in <7e3a59f5e4004edbb4b17c580799cc52>:0
at System.Text.Json.JsonEncodedText.TranscodeAndEncode (System.ReadOnlySpan1[T] value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00033] in <7e3a59f5e4004edbb4b17c580799cc52>:0 at System.Text.Json.JsonEncodedText.Encode (System.ReadOnlySpan1[T] value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00014] in <7e3a59f5e4004edbb4b17c580799cc52>:0
at System.Text.Json.JsonEncodedText.Encode (System.String value, System.Text.Encodings.Web.JavaScriptEncoder encoder) [0x00014] in <7e3a59f5e4004edbb4b17c580799cc52>:0
at System.Text.Json.JsonSerializer..cctor () [0x00042] in <7e3a59f5e4004edbb4b17c580799cc52>:0
--- End of inner exception stack trace ---

This was working fine in previous releases!

[DataContract]
public class UserIdentity
{
///


/// UserIdentity
///

public UserIdentity()
{
Header = DefaultHeader;
}

    #region Properties

    /// <summary>
    /// DefaultHeader
    /// </summary>
    public static string DefaultHeader = "ABA0";

    /// <summary>
    /// Header
    /// </summary>
    [DataMember]
    public string Header { get; set; }

    /// <summary>
    /// Login
    /// </summary>
    [DataMember]
    [Required]
    [EmailAddress]
    public string Login { get; set; }

    /// <summary>
    /// Name
    /// </summary>
    [DataMember]
    public string Name { get; set; }

    /// <summary>
    /// Password
    /// </summary>
    [DataMember]
    [Required]
    [DataType(DataType.Password)]
    public string Password { get; set; }

    /// <summary>
    /// User role
    /// </summary>
    [DataMember]
    public string Role { get; set; }

    /// <summary>
    /// Is valid
    /// </summary>
    [IgnoreDataMember]
    [JsonIgnore]
    public bool IsValid
    {
        get
        {
            return !string.IsNullOrEmpty(Login) && !string.IsNullOrEmpty(Password);
        }
    }

    #endregion
}
@filipnavara
Copy link
Member

The underlying issue: mono/mono#20805
Workaround is presented there.

@eltra-ch
Copy link
Author

Workaround doesn't work in my case. I applied 1:1 the references, but now I cannot use the "ReadOnlySpan" and "Span" classes. I don't know if this playes any role, but the those classes are used over .net standard 2.0 library.

@filipnavara
Copy link
Member

We also use .NET Standard 2.0 libraries. In the Xamarin main project we use the overrides for System.Buffers/System.Memory to convince NuGet that the dependency is satisfied without overwriting the actual files coming from the Mono/Xamarin framework.

@spouliot
Copy link
Contributor

Dupe of #10548

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants