Skip to content

Comments

Refactor GetManifestForRegisteredProvider to use XmlWriter#2353

Open
Copilot wants to merge 3 commits intomainfrom
copilot/refactor-xml-output-using-xmlwriter
Open

Refactor GetManifestForRegisteredProvider to use XmlWriter#2353
Copilot wants to merge 3 commits intomainfrom
copilot/refactor-xml-output-using-xmlwriter

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

The GetManifestForRegisteredProvider method hand-crafted XML through string concatenation and manual escaping. This refactoring replaces it with XmlWriter for better maintainability while ensuring identical output to the original implementation.

Changes

RegisteredTraceEventParser.cs

  • Introduced structured data model classes (EventData, TemplateData, DataField, MapData, MapEntry, StringTableEntry) to collect manifest data before serialization.
  • Replaced StringWriter-based XML concatenation with XmlWriter, which handles element nesting, attribute escaping, and namespace declarations automatically.
  • Removed manual XmlUtilities.XmlEscape calls that would have caused double-escaping when combined with XmlWriter.
  • Fixed a pre-existing bug where fields referencing a previously-seen map lost their map attribute (only the first field to discover a map received it).
  • Replaced ad-hoc delimiter-based template interning key with a structural TemplateKey class implementing IEquatable<TemplateKey> for collision-free template deduplication.
  • Removed unused using directives (System.Linq, Microsoft.Diagnostics.Utilities).
  • Fixed a typo in a comment ("Any es used so far" → "Any opcodes used so far").

RegisteredTraceEventParserTests.cs

  • Added GetManifestForRegisteredProvider_NoDoubleEscapedEntities: verifies no double-escaped XML entities in output and semantically compares string table entries between new and legacy
    implementations.
  • Added GetManifestForRegisteredProvider_NewAndLegacyImplementationsProduceSameOutput: normalizes and compares full XML output against a legacy reference implementation
    (Microsoft-JScript provider).
  • Added GetManifestForRegisteredProvider_DotNETRuntime_NewAndLegacyMatch: same comparison for the complex Microsoft-Windows-DotNETRuntime provider.
  • Added XML normalization helpers (NormalizeTemplateNames, RemoveNonSignificantTextNodes, SortAttributes) to handle formatting differences and template naming order between
    implementations.
  • Embedded a copy of the legacy string-based implementation for regression comparison.

Copilot AI changed the title [WIP] Refactor GetManifestForRegisteredProvider to use XmlWriter Refactor GetManifestForRegisteredProvider to use XmlWriter Jan 16, 2026
Copilot AI requested a review from brianrob January 16, 2026 01:07
@brianrob
Copy link
Member

@copilot, the new test is failing with the following error:

Testing provider: Microsoft-JScript (57277741-3638-4a4b-bdba-0ac6e45da56c)
New manifest length: 123505 chars
Legacy manifest length: 122634 chars
✓ New manifest is well-formed XML
✓ Legacy manifest is well-formed XML
✗ Normalized XML documents are different
Normalized new manifest length: 115979
Normalized legacy manifest length: 116091

First difference at position 3179:
New:    ...ts" /></keywords><tasks><task message="$(string.task_MethodRuntime)" name="MethodRuntime" value="1"><opcodes><opcode message="$(string.opcode_MethodRuntimeMethodLoad)" name="MethodLoad" value="10" /><...
Legacy: ...ts" /></keywords><tasks><task message="$(string.task_MethodRuntime)" name="MethodRuntime" value="1">
&gt;
      <opcodes><opcode message="$(string.opcode_MethodRuntimeMethodLoad)" name="MethodLoad" ...

Copy link
Contributor Author

Copilot AI commented Jan 16, 2026

@copilot, the new test is failing with the following error:

...

Fixed in commit c485a84. The issue was that stringIds (like keyword_{value}, task_{name}, etc.) were not being escaped with XmlUtilities.XmlEscape() in the new implementation, while the legacy code did escape them. This caused differences in stringId deduplication and attribute values. All stringId creations now use XmlUtilities.XmlEscape() to match legacy behavior.

@brianrob
Copy link
Member

@copilot, I've made a bunch of changes locally. Please update the PR description.

Copy link
Contributor Author

Copilot AI commented Feb 13, 2026

@copilot, I've made a bunch of changes locally. Please update the PR description.

Updated the PR description to reflect the changes made in commits 657a433, ab5f160, and 554069f:

Key updates:

  • Documented the multi-version event bug fix (events storage now uses List<EventData>)
  • Added info about moving legacy implementation to test file
  • Noted the two comprehensive test cases (Microsoft-JScript and DotNETRuntime)
  • Documented duplication of helper methods to keep production code private
  • Mentioned reversion of unrelated changes to other files
  • Removed notes about the > formatting quirk workaround (no longer needed with improved XML normalization)

The new description better reflects the current state of the PR with your improvements.

Replace hand-crafted XML string concatenation with XmlWriter for proper
XML generation. Add comparison tests against a copy of the legacy
implementation to validate output equivalence.

Changes:
- New XmlWriter-based implementation using structured data classes
  (EventData, TemplateData, DataField, MapData, MapEntry, StringTableEntry)
- Fix: events with multiple versions are now all preserved (List<EventData>)
- Fix: proper XML escaping via XmlWriter instead of manual escaping
- Legacy implementation preserved in test file for comparison testing
- Tests for Microsoft-JScript, Microsoft-Windows-Ntfs, and
  Microsoft-Windows-DotNETRuntime providers
@brianrob brianrob force-pushed the copilot/refactor-xml-output-using-xmlwriter branch from 554069f to d08077e Compare February 13, 2026 02:15
@brianrob brianrob marked this pull request as ready for review February 23, 2026 20:48
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