Fix premature returns for argument/pointer checks in SOSDacImpl.cs#124814
Merged
Fix premature returns for argument/pointer checks in SOSDacImpl.cs#124814
Conversation
Contributor
|
Tagging subscribers to this area: @agocke |
Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
…x GetPEFileName E_NOTIMPL Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix argument and pointer checks in SOSDacImpl.cs
Fix premature returns for argument/pointer checks in SOSDacImpl.cs
Feb 24, 2026
max-charlamb
approved these changes
Feb 24, 2026
Member
max-charlamb
left a comment
There was a problem hiding this comment.
lgtm, nice cleanup.
Especially good find on the bug in GetThreadFromThinlockID
rcj1
reviewed
Feb 24, 2026
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request refactors error handling in SOSDacImpl.cs by moving argument and pointer validation checks from before try blocks to inside try blocks, converting early returns to thrown exceptions. The goal is to ensure that the catch block can handle HResult conversion and that DEBUG comparison blocks work correctly.
Changes:
- Moved null pointer and invalid argument checks from before try blocks to inside try blocks across approximately 30 methods
- Changed early
return HResults.E_INVALIDARGstatements tothrow new ArgumentException()inside try blocks - Changed early
return HResults.E_POINTERstatements tothrow new NullReferenceException()inside try blocks - Restructured methods like
GetILForModule,GetMethodDescFromToken, andTraverseModuleMapfrom if/else structures to unified try/catch blocks - Added try/catch wrapper to
SOSMethodEnum.GetCount
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs
Show resolved
Hide resolved
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.
Description
Argument and pointer validation checks at the start of
SOSDacImplmethods were returning early (before thetry/catch), bypassing the catch block's HResult conversion and the#if DEBUGlegacy comparison block.Changes
try, replacedreturn HResults.E_INVALIDARGwiththrow new ArgumentException()try, replacedreturn HResults.E_POINTERwiththrow new NullReferenceException()if/elseguard patterns (ISOSDacInterface14 methods,GetILForModule,GetMethodDescFromToken,TraverseModuleMap) → flattened into unifiedtry/catchwith throwsdefault:cases (GetMethodDescFromToken,TraverseModuleMap) → replacedhr = HResults.E_INVALIDARGwiththrow new ArgumentException()so execution halts rather than falling throughGetPEFileName→ innerreturn HResults.E_NOTIMPLinsidetryreplaced withthrow new NotImplementedException()to preventCopyStringToBufferfrom running on empty pathsSOSMethodEnum.GetCount→ addedtry/catchwrapper;return HResults.E_POINTER→throw new NullReferenceException()GetThreadFromThinlockID→ fixed latent bug: null check was settinghrbut not preventing thetryblock from running, causing*pThreaddereference on a null pointerBefore / After pattern:
Testing
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.