Skip to content

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

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

Closed
jimmylearns opened this issue Sep 3, 2021 · 3 comments
Closed
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation

Comments

@jimmylearns
Copy link

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

@danmoseley danmoseley added the area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation label Sep 8, 2021
@MichalStrehovsky
Copy link
Member

There were breaking changes in the source generator APIs and looks like things are not fully stable yet.

I'm following up on one of the similar issues in dotnet/runtime#59042 (comment).

This should all stabilize as get close to .NET 6 RTM.

@jimmylearns
Copy link
Author

same problem with release version

@danmoseley danmoseley reopened this Nov 9, 2021
@jkotas
Copy link
Member

jkotas commented Nov 9, 2021

This works fine for me with .NET 6.0 RTM and the latest ilc package (7.0.0-alpha.1.21559.1).

It it does not work for you, please share the ilc package version that you are using and the build log.

Also, you may want to make sure to clean you obj and bin directories. The incremental builds do not always work correctly when .NET SDK version is updated.

@jkotas jkotas closed this as completed Nov 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation
Projects
None yet
Development

No branches or pull requests

4 participants