Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/UniGetUI.Core.Tools.Tests/MetaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ public void TestHttpClientInstantiation()
}
}

[Fact]
public void TestJsonSerializerContextsDoNotReuseSharedOptions()
{
var solutionDirectory = FindRepositoryRoot();
var csFiles = Directory
.GetFiles(solutionDirectory, "*.cs", SearchOption.AllDirectories)
.Where(file =>
!file.Contains(@"bin\")
&& !file.Contains(@"obj\")
&& !file.EndsWith(".g.cs")
&& !file.EndsWith("Tests.cs")
);

Regex forbiddenPattern = new(
@"JsonContext\s+\w+\s*=\s*new\(\s*SerializationHelpers\.DefaultOptions\s*\)",
RegexOptions.Multiline
);

foreach (var file in csFiles)
{
var fileContent = File.ReadAllText(file);
Assert.False(
forbiddenPattern.IsMatch(fileContent),
$"File {file} reuses SerializationHelpers.DefaultOptions when constructing a generated JsonSerializerContext. Clone the options first to avoid rebinding the shared resolver."
);
}
}

private static string FindRepositoryRoot()
{
DirectoryInfo? currentDirectory = new(AppDomain.CurrentDomain.BaseDirectory);
Expand Down
2 changes: 1 addition & 1 deletion src/UniGetUI/AutoUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public partial class AutoUpdater
];

private static readonly AutoUpdaterJsonContext ProductInfoJsonContext = new(
SerializationHelpers.DefaultOptions
new JsonSerializerOptions(SerializationHelpers.DefaultOptions)
);

public static Window Window = null!;
Expand Down