Skip to content

Fix TypeInfoResolver error for generated params types when using source-generated JsonSerializerContext#72

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-error-after-deploy-to-server
Draft

Fix TypeInfoResolver error for generated params types when using source-generated JsonSerializerContext#72
Copilot wants to merge 2 commits intomainfrom
copilot/fix-error-after-deploy-to-server

Conversation

Copy link
Contributor

Copilot AI commented Mar 13, 2026

After deploying to server, calling source-generated CgScript wrapper methods throws InvalidOperationException: TypeInfoResolver 'CgScriptSerializer' did not provide property metadata for type 'CgScriptExtensions+GetGridParams' — despite the README promising no [JsonSerializable] entries are needed for parameter types.

Root Cause

WrapperEmitter emitted JsonMetadataServices.CreateObjectInfo<GetGridParams>(ctx.Options, ...), passing the user's source-generated CgScriptSerializer context options. In .NET 8+, configuring the resulting JsonTypeInfo<T> triggers a TypeInfoResolver lookup for GetGridParams. Since that internal params record is never registered with CgScriptSerializer, the lookup throws.

Fix

The SerializeHandler lambda writes every property via hardcoded Utf8JsonWriter calls, so ctx.Options has zero effect on the serialized output. The generated CgScriptExtensions class now declares a shared static options field and uses it in place of ctx.Options:

// emitted into CgScriptExtensions
private static readonly global::System.Text.Json.JsonSerializerOptions _cgScriptParamsSerializerOptions =
    new(global::System.Text.Json.JsonSerializerDefaults.Web);

// ...inside each wrapper method:
var paramsInfo = JsonMetadataServices.CreateObjectInfo<GetGridParams>(_cgScriptParamsSerializerOptions, ...);

_cgScriptParamsSerializerOptions uses the DefaultJsonTypeInfoResolver (reflection-based), which handles any type without pre-registration, so the resolver lookup never reaches CgScriptSerializer for params types.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.antlr.org
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet /usr/share/dotnet/sdk/10.0.102/MSBuild.dll /noautoresponse /nologo /nodemode:1 /nodeReuse:true /low:false pport.Parsing/Catglobe.CgScript.EditorSupport.Parsing.csproj pport.CodeMirror.AspNet/Catglobe.CgScript.EditorSupport.CodeMirror.AspNet.csproj nt/Catglobe.CgScript.Deployment.csproj pport.SourceGenerator/Catglobe.CgScript.EditorSupport.SourceGenerator.csproj Catglobe.CgScript.Runtime.csproj ebApp/BlazorWebApp.csproj ebApp.Client/BlazorWebApp.Client.csproj pport.Lsp.Tests/Catglobe.CgScript.EditorSupport.Lsp.Tests.csproj pport.VsCode/Catglobe.CgScript.EditorSupport.VsCode.csproj pport.Lsp/Catglobe.CgScript.EditorSupport.Lsp.csproj pport.CodeMirror/Catglobe.CgScript.EditorSupport.CodeMirror.csproj atglobe.CgScript.Common.csproj pport.VisualStudio/Catglobe.CgScript.EditorSupport.VisualStudio.csproj (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

…lizerOptions in CreateObjectInfo

Co-authored-by: hientrung <6129457+hientrung@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error occurring after deploying to server Fix TypeInfoResolver error for generated params types when using source-generated JsonSerializerContext Mar 13, 2026
Copilot AI requested a review from hientrung March 13, 2026 05:28
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.

3 participants