-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 Source Generator not working with classes in global namespace #56970
Comments
Tagging subscribers to this area: @eiriktsarpalis, @layomia Issue DetailsDescriptionIf a class is defined in the global namespace, the JsonSerializerContext class code generation does not work. Steps to re-create this is as follows:
using System.Text.Json;
using System.Text.Json.Serialization;
string SerializeSourceGen() => JsonSerializer.Serialize(new Person("Vishvaka", "Ranasinghe", 28));
SerializeSourceGen();
public class Person
{
public Person(string firstName, string lastName, uint age)
{
FirstName = firstName;
LastName = lastName;
Age = age;
}
public string FirstName { get; set; }
public string LastName { get; set; }
public uint Age { get; set; }
}
[JsonSerializable(typeof(Person))]
internal partial class MyJsonContext : JsonSerializerContext
{
}
using Experiments;
using System.Text.Json;
string SerializeSourceGen() => JsonSerializer.Serialize(new Person("Vishvaka", "Ranasinghe", 28));
SerializeSourceGen();
using System.Text.Json.Serialization;
namespace Experiments
{
public class Person
{
public Person(string firstName, string lastName, uint age)
{
FirstName = firstName;
LastName = lastName;
Age = age;
}
public string FirstName { get; set; }
public string LastName { get; set; }
public uint Age { get; set; }
}
[JsonSerializable(typeof(Person))]
internal partial class MyJsonContext : JsonSerializerContext
{
}
}
Not having support for classes cause the need to create additional files with namespaces when trying to create a simple application using top-level statements.
|
Thanks. Dup of #56920. |
Description
If a class is defined in the global namespace, the JsonSerializerContext class code generation does not work.
Installed .NET SDK Version is: 6.0.100-preview.6.21355.2
Steps to re-create this is as follows:
Not having support for classes cause the need to create additional files with namespaces when trying to create a simple application using top-level statements.
The text was updated successfully, but these errors were encountered: