Skip to content

Fixes a code generation bug failed to generate the required XName fields in a C# class for an element#90

Merged
mamift merged 16 commits into
masterfrom
bug/paraparse
Jun 6, 2026
Merged

Fixes a code generation bug failed to generate the required XName fields in a C# class for an element#90
mamift merged 16 commits into
masterfrom
bug/paraparse

Conversation

@mamift

@mamift mamift commented Jun 5, 2026

Copy link
Copy Markdown
Owner
  • When a user specified CLR namespace ends with System or Xml, then the using directives in the generated code will now start with `global::`` to prevent namespace resolution errors and uncompilable code.
  • Fixed a code gen issue when an element definition is of a type that itself inherits from another type, the static XName fields that are usually generated for properties that are part of the element's content model, do not get generated at all. These are part of the element dictionary (BuildElementDictionary()) which is called in the static constructor for the that element class. This bug affects XObjectsCodeGen. Affected code generation for paraparse.xsd.

v3.4.16

mamift added 12 commits June 2, 2026 19:21
…pace ends with Xml or System, this causes compiler errors due to ambiguity.
…r occurred; this is necessary to distinguish identifiers that really do have numbers in their name, from identifiers that have simply have had numbers appended as suffix due to name collisions.
Fixed the following bug: when an element definition is of a type that itself inherits from another type, the static xname fields do not properly get generated as part of the element dictionary (BuildElementDictionary) which is called in the static constructor for the that element class.
@mamift mamift changed the title Fixes a code generation bug failed to generate the required XName fields in a C# class for an element. Fixes a code generation bug failed to generate the required XName fields in a C# class for an element Jun 5, 2026
@mamift mamift marked this pull request as ready for review June 5, 2026 11:19
Copilot AI review requested due to automatic review settings June 5, 2026 11:19

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 fixes an XObjectsCodeGen code-generation defect where wrapper element types could miss required static XName fields for content-model properties when the wrapped type participates in an inheritance chain. It also adds a repro/generated schema project (ParaParserXml) and bumps the package version to v3.4.16.

Changes:

  • Ensure XName fields are generated even when the property originates from a base type (so wrapper element types don’t rely on content-type inheritance).
  • Adjust generated using imports to add global:: when the generated CLR namespace would otherwise create ambiguity (notably when it ends with System/Xml).
  • Add ParaParserXml generated schema library + solution/test suite wiring; bump version and update release notes.

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
XObjectsCode/Src/TypesToCodeDom.cs Adds namespace-import disambiguation for generated code namespaces (prefix global:: when needed).
XObjectsCode/Src/TypeBuilder.cs Refactors local element dictionary property generation and minor CodeDOM statement construction changes.
XObjectsCode/Src/PropertyBuilder.cs Fixes missing XName field generation by not skipping base-origin properties.
XObjectsCode/Src/NameMangler.cs Refactors local symbol generation (adds SymbolIdentifier and adjusts collision handling helpers).
Version.props Bumps package version to 3.4.16.
RELEASENOTES.md Adds a new release entry for the change (needs a small correction per review comments).
LinqToXsdCore.sln Adds ParaParserXml project and updates solution metadata.
LinqToXsd/Properties/launchSettings.json Adds a launch profile to generate code for paraparse.xsd.
LinqToXsd-TestingSuite.slnf Includes the new ParaParserXml project in the testing solution filter.
GeneratedSchemaLibraries/ParaParserXml/ParaParserXml.csproj New generated schema library project for ParaParse; embeds schema/config/generated code.
GeneratedSchemaLibraries/ParaParserXml/paraparse.xsd.config Configuration mapping urn:ParaParse.XML to ParaParse.Xml.
GeneratedSchemaLibraries/ParaParserXml/paraparse.xsd Full ParaParse schema used for generation/regression coverage.
GeneratedSchemaLibraries/ParaParserXml/paraparse_xNameBug.xsd Minimal repro schema for the missing-XName bug scenario.
GeneratedSchemaLibraries/ParaParserXml/paraparse_xNameBug.xsd.cs Generated output for the minimal repro schema.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread RELEASENOTES.md Outdated
Comment thread RELEASENOTES.md
* https://www.nuget.org/packages/LinqToXsdCore/3.4.16
* https://www.nuget.org/packages/XObjectsCore/3.4.16
* [#88](https://github.com/mamift/LinqToXsdCore/pull/90).
* Fixed a code gen issue when an element definition is of a type that itself inherits from another type, the static `XName` fields that are usually generated for properties that are part of the element's content model, do not get generated at all. These are part of the element dictionary (`BuildElementDictionary()`) which is called in the static constructor for the that element class. This bug affects `XObjectsCodeGen`. Affected code generation for *paraparse.xsd*.
Comment thread XObjectsCode/Src/TypesToCodeDom.cs Outdated
Comment on lines +669 to +671
// at this point we need to check if adding global:: to any of the above namespace imports is necessary to avoid ambiguity with the
// generated code namespace. specifically what this fixes is that if the clrNamespace ends in a word that equals one of the starting
// words above (System or Xml), then a compiler errors are more likely to occur due to ambiguity between the namespace import and the generated code namespace
Comment thread GeneratedSchemaLibraries/ParaParserXml/ParaParserXml.csproj
mamift and others added 4 commits June 5, 2026 21:44
PR suggestion

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@mamift mamift merged commit bbdd9eb into master Jun 6, 2026
2 of 4 checks passed
@mamift mamift deleted the bug/paraparse branch June 6, 2026 01:20
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