Repository navigation
Serialize the PID file with a source-generated context so trimmed and AOT apps launch [patch] - #212
Open
matt-edmondson wants to merge 1 commit into
Open
matt-edmondson wants to merge 1 commit into
matt-edmondson wants to merge 1 commit into
Conversation
… AOT apps launch [patch] ShouldLaunch() read and wrote the PID file through reflection-based System.Text.Json, which an app published with PublishTrimmed or PublishAot runs with disabled, so the InvalidOperationException escaped and the app crashed on every launch. Both calls now use ProcessInfoJsonContext; the JSON shape is unchanged. IsAotCompatible on net7.0+ turns a future reflection call into a build error, and the test project runs with JsonSerializerIsReflectionEnabledByDefault=false so every test exercises that path. Fixes #210 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5Mwb7UBpSmjcYVryq
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #210
What was wrong
CheckPidFileContentsandWritePidFilecalled the reflection overloads ofJsonSerializer. Apps published withPublishTrimmedorPublishAotrun withJsonSerializer.IsReflectionEnabledByDefault=false, so both calls throwInvalidOperationException. Neither call site catches it, so it escapedShouldLaunch()/ExitIfAlreadyRunning()and the app crashed on every launch.Change
ProcessInfoJsonContext, a[JsonSerializable(typeof(ProcessInfo))]source-generated context. Both calls now go throughProcessInfoJsonContext.Default.ProcessInfo. The JSON shape is unchanged (same default options, PascalCase names), so PID files written by earlier versions still read.IsAotCompatibleon the net7.0+ targets. With it, reintroducing a reflection call fails the build: I checked by temporarily putting backJsonSerializer.Serialize(processInfo), which produced IL2026 and IL3050 errors. With the fix, the library builds with no warnings on any target.JsonSerializerIsReflectionEnabledByDefault=false, the runtimeconfig setting a trimmed or AOT app gets. Its mirrorProcessInfois read and written through a test-sideTestJsonContext, so every existing test now exercises the library the way those apps run it.The issue also mentions a separate trimmed-publish failure (
TypeLoadExceptioninktsu.Semantics.Paths.AbsoluteFilePath). That lives in Semantics and is out of scope here. The JIT repro from the issue, with reflection disabled in the runtimeconfig, is what this PR fixes and tests.Tests
Reflection-based serialization has been disabled for this application. Among them areShouldLaunch_WithNoExistingInstance_ShouldReturnTrue,ShouldLaunch_WhenAlreadyRunning_ShouldReturnFalseand theWritePidFile_*tests.dotnet pack -c Releasesucceeds, so package validation is happy.Generated by Claude Code