Prevent stack overflow on cyclic and XML types in TypeExt - #22
Merged
Merged
Conversation
temonk
commented
Aug 24, 2026
Contributor
- Update project version to 2.1.5 in Directory.Build.props
- Bump NuGet packages: AltaSoft.DomainPrimitives 8.1.2, Microsoft.NET.Test.Sdk 18.9.0, xunit.runner.visualstudio 4.0.0
- Refactor TypeExt.cs to detect cycles and treat XML types as leaf nodes
- Add XML type detection helpers and improve recursive property handling
- Add tests for XmlElement, XmlNode, and circular dependencies in SimpraMetaDataTest.cs
- Update project version to 2.1.5 in Directory.Build.props - Bump NuGet packages: AltaSoft.DomainPrimitives 8.1.2, Microsoft.NET.Test.Sdk 18.9.0, xunit.runner.visualstudio 4.0.0 - Refactor TypeExt.cs to detect cycles and treat XML types as leaf nodes - Add XML type detection helpers and improve recursive property handling - Add tests for XmlElement, XmlNode, and circular dependencies in SimpraMetaDataTest.cs
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Simpra metadata reflection utilities to avoid stack overflows when traversing cyclic object graphs and XML DOM types, adds regression tests for those scenarios, and bumps the project/package versions accordingly.
Changes:
- Refactors
TypeExt.ProcessPropertiesrecursion to introduce cycle detection and treat XML DOM types as leaf nodes. - Adds regression tests covering
XmlElement,XmlNode, and circular model references. - Updates project version and bumps core/testing NuGet dependencies.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
tests/AltaSoft.Simpra.tests/SimpraMetaDataTest.cs |
Adds regression tests and minimal repro models for XML and circular reference traversal. |
src/AltaSoft.Simpra.Metadata/TypeExt.cs |
Adds recursion tracking and XML-type leaf handling to prevent stack overflows during property expansion. |
Directory.Packages.props |
Bumps DomainPrimitives and test-related packages. |
Directory.Build.props |
Updates project version from 2.1.4 to 2.1.5. |
馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+77
to
90
| var actualType = Nullable.GetUnderlyingType(type) ?? type; | ||
|
|
||
| // Check for cycle: if type is already in visited path, skip expansion | ||
| // but still return the property with its actual type name | ||
| if (visited.Contains(actualType)) | ||
| { | ||
| return | ||
| [ | ||
| new PropertyModel | ||
| { | ||
| Name = name, | ||
| Description = type.GetSummaryWithoutException(), | ||
| Type = (Nullable.GetUnderlyingType(type) ?? type).AliasOrName(), | ||
| Required = isRequired | ||
| } | ||
| ]; | ||
| return [new PropertyModel | ||
| { | ||
| Name = name, | ||
| Description = type.GetSummaryWithoutException(), | ||
| Type = actualType.AliasOrName(), // Return actual type, not generic "object" | ||
| Required = isRequired | ||
| }]; | ||
| } |
Comment on lines
+92
to
+101
| // Skip XML types (System.Xml namespace) - treat as leaf nodes | ||
| if (IsXmlType(actualType)) | ||
| { | ||
| var enumType = Nullable.GetUnderlyingType(type) ?? type; | ||
| return | ||
| [ | ||
| new PropertyModel | ||
| { | ||
| Name = name, | ||
| Description = string.Join(" ", enumType.GetEnumNames()), | ||
| Type = "enum", | ||
| Required = isRequired | ||
| } | ||
| ]; | ||
| return [new PropertyModel | ||
| { | ||
| Name = name, | ||
| Description = type.GetSummaryWithoutException(), | ||
| Type = "object", // XML types are opaque - safe to use generic object | ||
| Required = isRequired | ||
| }]; |
Comment on lines
66
to
71
| var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public); | ||
| var processedProperties = properties | ||
| .Where(x => x.GetCustomAttribute<JsonIgnoreAttribute>() is null) | ||
| .Where(x => x.GetMethod is not null && x.CanRead) | ||
| .SelectMany(prop => Process(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) is null, prop.PropertyType)).Distinct().ToList(); | ||
| .SelectMany(prop => Process(prop.Name, Nullable.GetUnderlyingType(prop.PropertyType) is null, prop.PropertyType, visited)).Distinct().ToList(); | ||
|
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.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.