-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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 crashes when processing unresolved symbols #68072
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsDescriptionThe implementation of System.Text.Json source generation, in particular the mapping layer between Roslyn and System.Reflection types does not seem to handle unresolved symbols particularly well, resulting in crashes when they do turn up. Reproduction Stepsusing System.Text.Json;
using System.Text.Json.Serialization;
JsonSerializer.Serialize(new MyPoco(), MyContext.Default.MyPoco);
public class MyPoco
{
//[UnresolvedProperty] // uncomment to trigger crash
public int Prop { get; set; }
}
[JsonSerializable(typeof(MyPoco))]
public partial class MyContext : JsonSerializerContext
{
} Expected behaviorShould fail with a relevant error message. Actual behaviorCrashes with NullReferenceException:
Regression?No. Known WorkaroundsNo response ConfigurationNo response Other informationThe particular error message occurs because we are feeding a null
|
It's possible we might just want to do nothing in the case someone has customized their build to this point. If we can count on real compiler errors for unresolved symbols those are better than the source generator complaining it can't find types. Perhaps the only time we'd want the source generator to raise errors was when we were pretty certain that the build would otherwise be successful and the user might be actually trying to use JSON source generator (eg: has a System.Text.Json reference). |
In principle I agree, but I think we should at least try to exit gracefully when things don't type check. I'm not sure what prior art or best practices exist in the world of source generators. |
Hi! I've tried googling Where it comes from? Please, hint :) |
As its name hits, it comes nowhere. It triggers a compiling error because the name is undefined. A source generator should handle this gracefully, instead of crashing. |
Ahahahah, awkward moment 😀 |
Description
The implementation of System.Text.Json source generation, in particular the mapping layer between Roslyn and System.Reflection types does not seem to handle unresolved symbols particularly well, resulting in crashes when they do turn up.
Reproduction Steps
Expected behavior
Should fail with a relevant error message.
Actual behavior
Crashes with NullReferenceException:
Regression?
No.
Known Workarounds
No response
Configuration
No response
Other information
The particular error message occurs because we are feeding a null
AttributeConstructor
value to theConstructorInfoWrapper
type, which provides a mapping layer betweenIMethodSymbol
andSystem.Reflection.ConstructorInfo
.The text was updated successfully, but these errors were encountered: