Skip to content

Instantly share code, notes, and snippets.

@tiesmaster
Created February 21, 2023 12:55
Show Gist options
  • Select an option

  • Save tiesmaster/0d898ed7ca023aa415ca95314669ab66 to your computer and use it in GitHub Desktop.

Select an option

Save tiesmaster/0d898ed7ca023aa415ca95314669ab66 to your computer and use it in GitHub Desktop.
Failing serialization of stronglytyped id in dictionary
public class TestClass
{
[Fact]
public void MyTestMethod()
{
var dict = new Dictionary<UserId, string>();
var userId = UserId.New();
dict[userId] = "Yolo";
System.Text.Json.JsonSerializer.Serialize(dict);
}
}
[StronglyTypedId(backingType: StronglyTypedIdBackingType.Guid)]
public readonly partial struct UserId
{
public static UserId From(string id)
=> new(Guid.Parse(id));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment