Skip to content

System.Text.Json using source generators produces "Method not found" #1498

@jimmylearns

Description

@jimmylearns
using System.Text.Json;
using System.Text.Json.Serialization;
using NAOTJsonMissingMethod;

Sample sample = new();
JsonSerializer.Serialize(sample, SampleJsonContext.Default.Sample);

namespace NAOTJsonMissingMethod
{
    internal class Sample
    {
        public string Property { get; set; }
    }

    [JsonSerializable(typeof(Sample))]
    internal partial class SampleJsonContext : JsonSerializerContext
    {
        
    }
}

dotnet 6.0.100-preview.7
NativeAOT 7.0.0-alpha.1.21431.2

due the compilation stage it pops warning about missing method and then after running the published binary it throws:

Unhandled Exception: System.MissingMethodException: Method not found: 'System.Text.Json.Serialization.Metadata.JsonTypeInfo1<!!0> System.Text.Json.Serialization.Metadata.JsonMetadataServices.CreateObjectInfo(System.Text.Json.JsonSerializerOptions, System.Func1<!!0>, System.Func2<System.Text.Json.Serialization.JsonSerializerContext, System.Text.Json.Serialization.Metadata.JsonPropertyInfo[]>, System.Text.Json.Serialization.JsonNumberHandling, System.Action2<System.Text.Json.Utf8JsonWriter, !!0>)'.
at Internal.Runtime.TypeLoaderExceptionHelper.CreateMissingMethodException(ExceptionStringID, String) + 0x47
at Internal.Runtime.CompilerHelpers.ThrowHelpers.ThrowMissingMethodException(ExceptionStringID, String) + 0x6
at NAOTJsonMissingMethod.SampleJsonContext.get_Sample() + 0x12
at $.

$(String[]) + 0x2f
at NAOTJsonMissingMethod!+0x200305

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-NativeAOT-coreclr.NET runtime optimized for ahead of time compilation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions