Cleanup some C# warnings and dispose behavior. Make formatting more consistent.#823
Open
skottmckay wants to merge 2 commits into
Open
Cleanup some C# warnings and dispose behavior. Make formatting more consistent.#823skottmckay wants to merge 2 commits into
skottmckay wants to merge 2 commits into
Conversation
Make native logging more deterministic when running in debug mode. Should make the log outputs match up better so CI logs are easier to debug.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR is a focused cleanup of the C# SDK's IDisposable/warning hygiene plus a small native-logging tweak. It centralizes the pin→GCHandle ownership-transfer logic for "owned" items into a single helper, makes ItemQueue.Push leak-safe on failure, disables the noisy CA2000 analyzer (deferring to IDisposableAnalyzers), makes native log flushing more deterministic in debug, and refreshes the C# debug-binding instructions to match the existing RelWithDebInfo auto-detect.
Changes:
- Add
PinContext.PinForNativeDeleter(...)as the single ownership-transfer chokepoint (makesAllocForNativeDeletera private static helper) and routeBytesItem/ImageItem/AudioItemowned factories through it; reorderItemQueue.Pushso C#-side ownership is released only after a successful native push. - Disable CA2000 project-wide (NoWarn in both csprojs +
.editorconfignone), documenting that IDisposableAnalyzers is the disposal-correctness authority. - Flush native logs on every message in debug builds or when Debug/Verbose is requested; add a
memories/repodoc and update the C#-debug-binding instructions (Debug → RelWithDebInfo).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| sdk_v2/cs/src/Items/PinContext.cs | New PinForNativeDeleter chokepoint; AllocForNativeDeleter becomes private static; single IDISP001 suppression. |
| sdk_v2/cs/src/Items/ItemQueue.cs | Push now calls native first and releases ownership only on success, avoiding handle leak on failure. |
| sdk_v2/cs/src/Items/BytesItem.cs | Owned factory routes through PinForNativeDeleter; pragma suppressions removed; namespace/using reordered. |
| sdk_v2/cs/src/Items/ImageItem.cs | Same owned-factory refactor and header reorder as BytesItem. |
| sdk_v2/cs/src/Items/AudioItem.cs | Both owned factories route through PinForNativeDeleter; header reorder. |
| sdk_v2/cs/src/Microsoft.AI.Foundry.Local.csproj | Adds NoWarn;CA2000 with rationale. |
| sdk_v2/cs/test/FoundryLocal.Tests/...Tests.csproj | Adds NoWarn;CA2000 for the test project. |
| sdk_v2/cs/.editorconfig | CA2000 severity downgraded from warning to none with rationale. |
| sdk_v2/cpp/src/spdlog_logger.cc | Flush-every-message in debug builds or Debug/Verbose level; otherwise flush at warning+. |
| memories/repo/cs-item-ownership-transfer.md | New doc capturing the C# item ownership/CA2000 model. |
| .github/instructions/cs-debug-binding.instructions.md | Updates guidance from Debug to RelWithDebInfo to match csproj auto-detect. |
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.
Suggest turning off whitespace diffs when reviewing.