[cDAC] Adding TryGetContract on ContractRegistry to allow more custom behavior if contract is not found#127019
Merged
rcj1 merged 3 commits intodotnet:mainfrom Apr 17, 2026
Merged
Conversation
TryGetContract on ContractRegistry to allow more custom behavior if contract is not foundTryGetContract on ContractRegistry to allow more custom behavior if contract is not found
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a TryGetContract API to the cDAC ContractRegistry so callers can handle “contract not available” without relying on NotImplementedException control flow.
Changes:
- Introduces
ContractRegistry.TryGetContract<TContract>(out TContract, out string? failureReason)and routes existing property access through a throwing helper. - Updates
CachingContractRegistryand the testTestContractRegistryto implementTryGetContract. - Updates
SOSDacImpl.GetTieredVersionsto useTryGetContract<IReJIT>to returnS_OKwhen ReJIT isn’t supported.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/ContractRegistry.cs | Adds TryGetContract and changes how GetContract is exposed/used. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/CachingContractRegistry.cs | Implements TryGetContract for descriptor-backed resolution and caching. |
| src/native/managed/cdac/tests/TestPlaceholderTarget.cs | Updates test contract registry to the new TryGetContract pattern. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/SOSDacImpl.cs | Switches GetTieredVersions feature-gating from exceptions to TryGetContract. |
f9e7c04 to
6fcb482
Compare
6fcb482 to
1beed55
Compare
…er.Abstractions/ContractRegistry.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
max-charlamb
approved these changes
Apr 16, 2026
noahfalk
reviewed
Apr 16, 2026
jkoritzinsky
approved these changes
Apr 17, 2026
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.
Currently, we access the contracts through GetContract, which throws NotImplementedException if the contract is not found. In the vast majority of cases, this fits neatly into the desired behavior - either we use this contract as part of an API that is supposed to return
E_NOTIMPLwhen the feature is not enabled, or it is a catastrophic failure if the contract is not found, or both. However, a small subset of APIs have different behavior - we want to, say, returnS_OKor branch and try another behavior. Currently, doing this requires our control flow to rely on these exceptions. This seeks to eliminate this pattern; in the rare case when a caller wants a different behavior, it can callTryGetContractand handle the true and false cases in a custom way.More context: #126963 (comment)