From f97890c1c5491bbd72e7a61e54b8a3e6ee1ff0e3 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Wed, 15 Jan 2025 16:45:30 -0800 Subject: [PATCH] Allow nested types inside of the type - This isn't disallowed by spec, although ilasm and ildasm cannot handle these cases - Simply skip adding the type to the available class hash. Backport of bugfix portion of PR #111435 Fixes #111164 in .NET 9 --- src/coreclr/vm/clsload.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/coreclr/vm/clsload.cpp b/src/coreclr/vm/clsload.cpp index 0c42ca20161eee..02eecdcafd0b30 100644 --- a/src/coreclr/vm/clsload.cpp +++ b/src/coreclr/vm/clsload.cpp @@ -3482,6 +3482,12 @@ VOID ClassLoader::AddAvailableClassHaveLock( if (SUCCEEDED(pMDImport->GetNestedClassProps(classdef, &enclosing))) { // nested type + if (enclosing == COR_GLOBAL_PARENT_TOKEN) + { + // Types nested in the class can't be found by lookup. + return; + } + COUNT_T classEntryIndex = RidFromToken(enclosing) - 1; _ASSERTE(RidFromToken(enclosing) < RidFromToken(classdef)); if (classEntries->GetCount() > classEntryIndex)