Skip to content

Fix UTF-8 string marshaling in C# bindings (#5694) - #5709

Draft
wnykuang wants to merge 2 commits into
NatLabRockies:developfrom
wnykuang:fix/csharp-utf8-5694
Draft

wnykuang wants to merge 2 commits into
NatLabRockies:developfrom
wnykuang:fix/csharp-utf8-5694

Conversation

@wnykuang

Copy link
Copy Markdown
Contributor

Fixes #5694.

C# string marshaling can corrupt Unicode paths on Windows, causing save() to succeed at a different path. Ordinary text and returned strings are also affected.

Use explicit UTF-8 marshaling for string arguments, return values, and SWIG callbacks, with .NET Framework 4.5-compatible conversion code. Add a Windows CTest regression for paths, IDF load/save, text, containers, and exceptions.

Testing

  • Clean Windows x86/x64 builds of the 3.12.0-alpha C# SDK, including native libraries, and UTF-8 CTest passed. CI run
  • Downloaded artifacts passed local Windows tests on .NET Framework x86/x64 and .NET 10 x64.
  • Clean WSL build and regression passed.

Contribution documentation

The completed contribution proposal for this fix is being submitted to David for review.

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.

🟢 Approval recommended

No active review issues are reported for the C# UTF-8 marshaling changes.

No open issues 🎉

What changed in this PR

This PR addresses #5694 by making C# binding string marshaling explicitly UTF-8, preventing Unicode path and text corruption on Windows while retaining .NET Framework 4.5 compatibility.

Changes:

  • Adds UTF-8 marshaling for string arguments, return values, and SWIG callbacks.
  • Integrates the marshaler and callback configuration into binding generation and SDK builds.
  • Adds a Windows regression test covering Unicode paths, IDF load/save, text, containers, and exceptions.
File Description
src/​utilities/​core/​csharp/​Utf8.i Defines UTF-8 string marshaling typemaps.
src/​utilities/​core/​csharp/​LanguageSpecific.i Includes the UTF-8 typemaps.
src/​utilities/​CMakeLists.txt Registers the new typemap source.
ProjectMacros.cmake Runs callback configuration after SWIG generation.
csharp/​Utf8Marshaler.cs Implements UTF-8 conversion and native buffer ownership.
csharp/​test/​Utf8Bindings.cs Adds Unicode binding regression checks.
csharp/​test/​RunUtf8Bindings.cmake Compiles and runs the regression executable.
csharp/​test/​README.md Documents test execution and marshaling ownership.
csharp/​developer/​OpenStudio/​OpenStudio.csproj.in Includes the marshaler in the managed project.
csharp/​ConfigureUtf8Callbacks.cmake Applies UTF-8 marshaling attributes to generated callbacks.
csharp/​CMakeLists.txt Tracks managed build dependencies and registers the Windows CTest.

Review effort: Balanced

@anchapin anchapin added the Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge. label Nov 16, 2026
@wnykuang
wnykuang marked this pull request as draft November 17, 2026 00:43
@wnykuang

Copy link
Copy Markdown
Contributor Author

will do a final review and update docs on weekends; I think there should be a better approach.

@ci-commercialbuildings

ci-commercialbuildings commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

CI Results for 0451b30:

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Pull Request - Ready for CI This pull request if finalized and is ready for continuous integration verification prior to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Paths containing U+2013 (en dash) handled incorrectly

4 participants