Skip to content

Initialize generated subscription list lazily so MapTo works after deserialization - #151

Open
armadavalor wants to merge 1 commit into
hadashiA:mainfrom
armadavalor:fix/58-lazy-subscriptions-list
Open

armadavalor wants to merge 1 commit into
hadashiA:mainfrom
armadavalor:fix/58-lazy-subscriptions-list

Conversation

@armadavalor

Copy link
Copy Markdown

The generated vitalRouterGeneratedSubscriptions was a readonly field with an initializer. Initializers are skipped when an instance is created without running a constructor (JSON/binary deserializers, FormatterServices.GetUninitializedObject), so the field stayed null and MapTo / UnmapRoutes threw NullReferenceException / ArgumentNullException on lock (null).

The field is now created lazily in MapTo (LazyInitializer.EnsureInitialized, thread-safe), and UnmapRoutes returns early if it was never created.

Verification: added MapToWorksOnInstanceCreatedWithoutConstructor to GeneratedRoutingTest. It fails before the change and passes after. The machine only had the .NET 7 SDK (the test project targets net9.0, the generator uses LangVersion 13), so I ran GeneratedRoutingTest in a scratch net7.0 project compiling the repo sources: Passed! - Failed: 0, Passed: 12, Skipped: 0, Total: 12. I did not run the full suite or Unity.

Closes #58

@vercel

vercel Bot commented Oct 25, 2026

Copy link
Copy Markdown

@armadavalor is attempting to deploy a commit to the hadashia's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After deserialization, vitalRouterGeneratedSubscriptions becomes null.

1 participant