Skip to content

give a clear TypeLoadException when a TypeBuilder type was never created - #136436

Merged
jkotas merged 5 commits into
dotnet:mainfrom
lagudafuadtosin:fix-101322
Oct 27, 2026
Merged

jkotas merged 5 commits into
dotnet:mainfrom
lagudafuadtosin:fix-101322

Conversation

@lagudafuadtosin

@lagudafuadtosin lagudafuadtosin commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

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.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 25, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection
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.

🟢 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 TypeLoadException for 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

Comment thread src/coreclr/dlls/mscorrc/mscorrc.rc Resolved

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.

🔵 Needs a closer look

Cross-runtime loader and native-to-managed exception propagation changes warrant maintainer confirmation beyond the available static review evidence.

No open issues 🎉

Review effort: Balanced

Comment thread src/coreclr/dlls/mscorrc/mscorrc.rc Resolved
… as an error so the tests also run in the browser

@jkotas jkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@jkotas
jkotas merged commit a58ea1c into dotnet:main Oct 27, 2026
148 of 150 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Reflection community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhelpful error message for missing TypeBuilder.CreateType() call

3 participants