feat: generator-emitted DTO constructor lambdas for IL trimming#50
Merged
feat: generator-emitted DTO constructor lambdas for IL trimming#50
Conversation
The source generator now discovers plain DTO return types from factory method signatures and emits DtoConstructorRegistry.Register<T>(() => new T()) calls with [DynamicallyAccessedMembers(All)] to preserve the type from IL trimming. NeatooJsonTypeInfoResolver uses the registry instead of Activator.CreateInstance, which fails under trimming. This fixes DTO deserialization in trimmed Blazor WASM apps where IsTrimmable=true causes DefaultJsonTypeInfoResolver's reflection-based constructor/property discovery to fail. Also fixes Design.Client.Blazor index.html script tag placeholder. Closes #48 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Explains why IsTrimmable=true breaks DefaultJsonTypeInfoResolver for plain DTOs and how the generator automatically preserves them. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
DtoConstructorRegistry.Register<T>(() => new T())calls[DynamicallyAccessedMembers(All)]onRegister<T>preserves the entire type from IL trimmingNeatooJsonTypeInfoResolveruses the registry instead ofActivator.CreateInstance(which fails under trimming)IsTrimmable=trueon domain assemblies causesDefaultJsonTypeInfoResolver's reflection-based discovery to failCloses #48
Why this is needed
Normal Blazor WASM apps don't hit this because their assemblies aren't trimmed (
TrimMode=partialonly trimsIsTrimmable=trueassemblies). RemoteFactory intentionally marks domain assemblies trimmable to remove server-only business logic from the client — a core value proposition. This meansDefaultJsonTypeInfoResolver's reflection breaks for plain DTOs.Verified
Design.Serverin Release/net10.0, loaded in browser, clicked "Get All Items" and "Get Item fix: trimming-safe factory registration for all factory types #42" —ExampleDtodeserialized with correctIdandNamevalues under IL trimmingTest plan
ExampleRecordResultexcluded from registry)CreateObject)🤖 Generated with Claude Code