-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Improve TypeBuilderInstantiation error messages to guide users to TypeBuilder static methods #118638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…eBuilder static methods Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
Outdated
Show resolved
Hide resolved
|
@copilot Please address the feedback above |
… messages where appropriate Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
|
@copilot Please address the feedback above |
…zed resource string Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
Outdated
Show resolved
Hide resolved
....Reflection.Emit/tests/PersistedAssemblyBuilder/TypeBuilderInstantiationErrorMessageTests.cs
Outdated
Show resolved
Hide resolved
....Reflection.Emit/tests/PersistedAssemblyBuilder/TypeBuilderInstantiationErrorMessageTests.cs
Outdated
Show resolved
Hide resolved
....Reflection.Emit/tests/PersistedAssemblyBuilder/TypeBuilderInstantiationErrorMessageTests.cs
Outdated
Show resolved
Hide resolved
....Reflection.Emit/tests/PersistedAssemblyBuilder/TypeBuilderInstantiationErrorMessageTests.cs
Outdated
Show resolved
Hide resolved
....Reflection.Emit/tests/PersistedAssemblyBuilder/TypeBuilderInstantiationErrorMessageTests.cs
Outdated
Show resolved
Hide resolved
....Reflection.Emit/tests/PersistedAssemblyBuilder/TypeBuilderInstantiationErrorMessageTests.cs
Outdated
Show resolved
Hide resolved
…ilder/TypeBuilderInstantiationErrorMessageTests.cs
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
…peBuilder directory Co-authored-by: jkotas <6668460+jkotas@users.noreply.github.com>
src/libraries/System.Private.CoreLib/src/Resources/Strings.resx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
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 improves error messages for TypeBuilderInstantiation objects created when calling MakeGenericType() on a TypeBuilder. Previously, attempting to access constructors, methods, or fields on these instantiated types would throw generic "Specified method is not supported" errors. Now they provide helpful guidance directing users to the appropriate TypeBuilder static methods.
Key changes:
- Enhanced error messages to guide users to
TypeBuilder.GetConstructor,TypeBuilder.GetMethod, andTypeBuilder.GetFieldstatic methods - Added comprehensive test coverage to validate the improved error messages
- Maintained backward compatibility while significantly improving developer experience
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
TypeBuilderInstantiationErrorMessageTests.cs |
New test file validating improved error messages for TypeBuilderInstantiation member access |
TypeBuilderInstantiation.cs |
Updated constructor, method, and field access methods to use helpful error messages |
Strings.resx |
Added new resource string for TypeBuilderInstantiation error messages |
src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/TypeBuilderInstantiation.cs
Outdated
Show resolved
Hide resolved
|
Tagging subscribers to this area: @dotnet/area-system-reflection-emit |
…t/TypeBuilderInstantiation.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
...raries/System.Reflection.Emit/tests/TypeBuilder/TypeBuilderInstantiationErrorMessageTests.cs
Outdated
Show resolved
Hide resolved
…lderInstantiationErrorMessageTests.cs
|
/ba-g helix infrastructure failures without logs. |
When using
PersistedAssemblyBuilderto create generic types, callingMakeGenericType()returns aTypeBuilderInstantiationobject. Previously, attempting to access members like constructors, methods, or fields on this instantiated type would throw unhelpfulNotSupportedExceptionmessages like "Specified method is not supported."This PR improves the error messages to provide clear guidance on how to properly access members using the static
TypeBuildermethods:Before:
After:
Changes made:
Added error message resources to
Strings.resxfor methods that have correspondingTypeBuilderstatic alternatives:NotSupported_TypeBuilderInstantiation_GetConstructorNotSupported_TypeBuilderInstantiation_GetMethodNotSupported_TypeBuilderInstantiation_GetFieldUpdated error messages for methods that have
TypeBuilderstatic alternatives:GetConstructor*methods → Direct users toTypeBuilder.GetConstructorGetMethod*methods → Direct users toTypeBuilder.GetMethodGetField*methods → Direct users toTypeBuilder.GetFieldMaintained default error messages for methods that don't have
TypeBuilderequivalents (Interface, Event, Property, NestedType operations) to avoid providing misleading guidance.Added comprehensive tests to validate the improved error messages and ensure the suggested workarounds continue to function correctly.
The correct workaround is to use the static
TypeBuildermethods:This change maintains full backward compatibility while significantly improving the developer experience by providing actionable guidance when encountering this limitation.
Fixes #118506.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.