Repository navigation
give a clear TypeLoadException when a TypeBuilder type was never created - #136436
Merged
Merged
Conversation
lagudafuadtosin
requested review from
steveisok and
vitek-karas
as code owners
October 25, 2026 12:14
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The changes target existing failure paths and include focused regression coverage, with no unresolved review findings.
No open issues 🎉
What changed in this PR
Improves Reflection.Emit diagnostics for types whose TypeBuilder.CreateType() was never called, addressing #101322 across CoreCLR and Mono.
Changes:
- Reports an actionable
TypeLoadExceptionfor uncreated types while preserving unrelated failure paths. - Adds matching diagnostic resources for both runtimes.
- Adds a regression test that invokes a created type referencing an uncreated nested type and checks the exception and guidance.
| File | Description |
|---|---|
src/mono/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.Mono.cs |
Throws the targeted exception during runtime resolution. |
src/libraries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderDefineNestedType.cs |
Tests the uncreated nested-type diagnostic. |
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx |
Adds the managed diagnostic message. |
src/coreclr/vm/clsload.cpp |
Selects the targeted diagnostic in the type-loading failure path. |
src/coreclr/dlls/mscorrc/resource.h |
Defines the native diagnostic resource identifier. |
src/coreclr/dlls/mscorrc/mscorrc.rc |
Adds the matching CoreCLR diagnostic message. |
Review effort: Balanced
jkotas
reviewed
Oct 26, 2026
…op mono aborting on an uncreated type
jkotas
reviewed
Oct 26, 2026
jkotas
reviewed
Oct 26, 2026
… as an error so the tests also run in the browser
This was referenced Oct 26, 2026
…aded, instead of asserting
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.
fixes #101322
Using a type whose TypeBuilder.CreateType was never called gave "Could not load type 'X' from assembly 'Y'." on coreclr and "The invoked member is not supported in a dynamic module." on mono.
With this fix both now throw a TypeLoadException saying the type has not been created and to call TypeBuilder.CreateType.
Tested: new test fails on main and passes with the fix on coreclr and mono.
Why not change the general throw at the end of LoadTypeDefThrowing? Other failures reach that throw too, for example a generic type definition used without its type arguments, and they would be told the type was not created.
On mono, check_created is not changed because like other members use it, and for them not supported is still the right message.