Repository navigation
Description
Component
Microsoft.Diagnostics.DataContractReader (cDAC) — RuntimeTypeSystem contract / DBI legacy layer.
Summary
When cDAC reconstructs a loaded generic instantiation (GetConstructedType for ELEMENT_TYPE_GENERICINST), it searches for the instantiation only in the AvailableParamTypes table of the generic definition's loader module. The runtime, however, assigns a generic instantiation to a loader module computed from all of its type arguments (ClassLoader::ComputeLoaderModule). When a type argument's loader module differs from the definition's — most notably when an argument lives in a collectible AssemblyLoadContext — the instantiation is registered in that other module's table, so cDAC looks in the wrong place and fails to resolve the type. The legacy DAC resolves it correctly, so this is a cDAC-vs-DAC divergence.
Affected code
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs
// GetConstructedType (~line 1262)
loaderModule = GetLoaderModule(typeHandle); // typeHandle = the OPEN generic definition
ModuleHandle moduleHandle = loaderContract.GetModuleHandleFromModulePtr(loaderModule);
foreach (TargetPointer ptr in loaderContract.GetAvailableTypeParams(moduleHandle)) // searches ONE module
{
if (corElementType == CorElementType.GenericInst &&
GenericInstantiationMatch(typeHandle, potentialMatch, typeArguments) && IsLoaded(potentialMatch))
return potentialMatch;
...
}
return new TypeHandle(TargetPointer.Null); // not found → caller sees "class not loaded"GetLoaderModule(TypeHandle) (~line 1420) for a MethodTable returns the type's own stored loader module (the definition's module); it does not consider type arguments.
Expected behavior
The loaded instantiation should be located using the same loader-module algorithm the runtime uses to register it — ClassLoader::ComputeLoaderModuleWorker in src/coreclr/vm/clsload.cpp:98:
- Start from the definition module.
- If any class/method type argument is in a collectible module, select the module of the latest-created collectible loader allocator among the arguments (
clsload.cpp:156-193). - Otherwise fall back to the definition module (CoreLib when null).
cDAC should compute the loader module from the type arguments (mirroring ComputeLoaderModuleWorker) before searching GetAvailableTypeParams, or otherwise search the correct module's table.
Actual behavior
GetConstructedType searches only GetLoaderModule(definition)'s AvailableParamTypes. For an instantiation whose real loader module is an argument's (collectible/ALC) module, the match is not found and GetConstructedType returns a null TypeHandle. Downstream this surfaces as a failure to resolve the type / read fields of such an object under the debugger, where the legacy DAC succeeds.
Impact
Debugging (ICorDebug / DBI over cDAC, DOTNET_ENABLE_CDAC=1) of any object whose type is a generic instantiation with a type argument from a different — especially collectible/AssemblyLoadContext — assembly. Reproduces cleanly with async state machines, because the compiler-generated state-machine struct is often defined in a different assembly than AsyncTaskMethodBuilder/Task<T>, producing AsyncStateMachineBox<TResult, TStateMachine> where TStateMachine comes from another (collectible) ALC. Inspecting such a box's fields (e.g. StateMachine) via ICorDebugObjectValue::GetFieldValue fails under cDAC while succeeding under the legacy DAC.
Repro sketch
- App loads an assembly into a collectible
AssemblyLoadContextthat defines anasyncmethod (its state machine struct lives in that ALC's assembly). - Break while such a task is live and have the debugger inspect the async continuation / the
AsyncStateMachineBox<…, StateMachineFromOtherAssembly>object's fields. - Run once with
DOTNET_ENABLE_CDAC=0(works) and once withDOTNET_ENABLE_CDAC=1(fails to resolve the instantiation).
Suggested fix
Implement the ComputeLoaderModule algorithm in the cDAC RuntimeTypeSystem contract (type-argument-driven, with the collectible "latest loader allocator" rule) and use it in GetConstructedType to choose which module's GetAvailableTypeParams to search — instead of GetLoaderModule(definition). A DumpTests case using a generic instantiated with a type argument from a collectible ALC would guard the regression.
Notes
- Discovered via post-mortem analysis of a debugger-host crash while inspecting an async state machine whose
StateMachinefield type came from another assembly;ICorDebugObjectValue::GetFieldValuereturnedE_INVALIDARGunder cDAC. The exact HRESULT depends on which consumer receives the unresolved type (the type-reconstruction path itself yieldsCORDBG_E_CLASS_NOT_LOADED); the common root is the loader-module mismatch above.
Activity
dotnet-policy-service commentedon Jul 2, 2026
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.
Fix cDAC generic instantiation loader module resolution for collectib…
Consolidate FnPtr/GenericInst loader-module logic into shared Compute…
Fix cDAC generic instantiation loader module resolution for collectib…
Add CollectibleGenericInst dump test for #130143 loader-module fix
Finalize CollectibleGenericInst dump test for #130143
[cDAC] Fix `#130143` - search correct loader module for generic insta…
[cDAC] Fix `#130143` - search correct loader module for generic insta…