Skip to content

[cDAC] Ensure mt created#129114

Merged
rcj1 merged 1 commit into
dotnet:mainfrom
rcj1:ensure-mt-created
Jun 8, 2026
Merged

[cDAC] Ensure mt created#129114
rcj1 merged 1 commit into
dotnet:mainfrom
rcj1:ensure-mt-created

Conversation

@rcj1

@rcj1 rcj1 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Before checking the dict of MTs when not coming directly from a constructed TypeHandle, ensure that the MethodTable is created.

Copilot AI review requested due to automatic review settings June 8, 2026 04:22
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

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.

Pull request overview

This PR updates the cDAC RuntimeTypeSystem_1 contract implementation to ensure a MethodTable is validated/created/cached before dereferencing _methodTables[...] in code paths that start from a MethodDesc (rather than from an already-constructed TypeHandle). This reduces the chance of runtime failures (e.g., KeyNotFoundException) when querying generic context/metadata-related properties for a method.

Changes:

  • Route MethodDesc-based MethodTable lookups through GetOrCreateMethodTable(methodDesc) instead of directly indexing _methodTables[methodDesc.MethodTable].
  • Apply this in generic context location evaluation and in the abstract-method metadata check.
Show a summary per file
File Description
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs Ensures MethodTable is created/cached before dereferencing _methodTables when starting from MethodDesc-driven paths.

Copilot's findings

Comments suppressed due to low confidence (1)

src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs:1353

  • This change fixes a previously possible KeyNotFoundException when GetGenericContextLoc (via RequiresInstArgMethodTable / IsSharedByGenericInstantiations / IsAbstract) is invoked for a MethodDescHandle whose owning MethodTable hasn't been cached yet (e.g., after GetMethodDescHandle without any prior GetTypeHandle). There are existing cDAC unit tests for IRuntimeTypeSystem/MethodDesc behavior, but none appear to cover this regression. Please add a targeted unit test that calls GetMethodDescHandle(...) and then GetGenericContextLoc(...) without pre-caching the MethodTable, and asserts it does not throw and returns the expected GenericContextLoc for the constructed mock MethodTable/method.
        MethodTable mt = GetOrCreateMethodTable(methodDesc);
        if (mt.Flags.IsValueType)
            return true;

        if (mt.Flags.IsInterface && !IsAbstract(methodDesc))
            return true;
  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@rcj1 rcj1 merged commit a3e0275 into dotnet:main Jun 8, 2026
60 of 64 checks passed
@rcj1 rcj1 deleted the ensure-mt-created branch June 8, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants