Skip to content

Prevent stack overflow on cyclic and XML types in TypeExt - #22

Merged
temonk merged 2 commits into
mainfrom
bugfix/circularDependency
Aug 24, 2026
Merged

temonk merged 2 commits into
mainfrom
bugfix/circularDependency

Conversation

@temonk

@temonk temonk commented Aug 24, 2026

Copy link
Copy Markdown
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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ProcessProperties recursion 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();

Comment thread src/AltaSoft.Simpra.Metadata/TypeExt.cs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@temonk
temonk merged commit 1cdc820 into main Aug 24, 2026
1 check passed
@temonk
temonk deleted the bugfix/circularDependency branch August 24, 2026 08:36
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.

2 participants