Skip to content

feat: add AutoDiscoverKnownTypes to auto-register constant types#183

Merged
esskar merged 1 commit into
mainfrom
feature/issue-158-auto-discover-known-types
Jun 16, 2026
Merged

feat: add AutoDiscoverKnownTypes to auto-register constant types#183
esskar merged 1 commit into
mainfrom
feature/issue-158-auto-discover-known-types

Conversation

@esskar

@esskar esskar commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Serializing an expression that captures a custom type or enum value previously threw "Error converting type" unless the caller registered each type via AddKnownType, because the DataContractSerializer requires polymorphic constant types to be known.

Add an opt-in AutoDiscoverKnownTypes flag on the serializers (and ExpressionSerializer). When enabled, the node tree is walked at serialize time and the runtime types of constant values (plus their array element / generic argument types) are registered automatically. Discovery inspects types statically and never enumerates the constant values, so lazy sequences such as IQueryable are not executed.

The option is off by default, so existing behavior is unchanged.

Closes #158

Serializing an expression that captures a custom type or enum value
previously threw "Error converting type" unless the caller registered
each type via AddKnownType, because the DataContractSerializer requires
polymorphic constant types to be known.

Add an opt-in AutoDiscoverKnownTypes flag on the serializers (and
ExpressionSerializer). When enabled, the node tree is walked at
serialize time and the runtime types of constant values (plus their
array element / generic argument types) are registered automatically.
Discovery inspects types statically and never enumerates the constant
values, so lazy sequences such as IQueryable are not executed.

The option is off by default, so existing behavior is unchanged.

Closes #158

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@esskar esskar merged commit c391a70 into main Jun 16, 2026
1 check passed
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.

Error converting type: Bug or implementation issue - please help

1 participant