-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[UUF] Update TypeBuilder.DefineMethodOverride code examples to target .NET 9 #11963
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
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
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 updates the code examples for TypeBuilder.DefineMethodOverride to target .NET 9 instead of .NET Framework 4.8, making them compilable and runnable on modern .NET versions. The changes replace deprecated .NET Framework-specific APIs with their modern equivalents while preserving the educational purpose of demonstrating explicit interface implementation with dynamic types.
Key Changes:
- Migrated from .NET Framework 4.8 to .NET 9 with modern API patterns
- Replaced
AppDomain.CurrentDomain.DefineDynamicAssembly()withAssemblyBuilder.DefineDynamicAssembly() - Removed assembly persistence functionality (
Save()method) which is not supported in .NET Core+
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| snippets/csharp/System.Reflection.Emit/TypeBuilder/DefineMethodOverride/Project.csproj | Updated target framework from net48 to net9.0 and changed OutputType from Library to Exe |
| snippets/csharp/System.Reflection.Emit/TypeBuilder/DefineMethodOverride/source.cs | Modernized reflection emit APIs and removed assembly save functionality |
| snippets/visualbasic/System.Reflection.Emit/TypeBuilder/DefineMethodOverride/Project.vbproj | Created new project file targeting net9.0 as an executable |
| snippets/visualbasic/System.Reflection.Emit/TypeBuilder/DefineMethodOverride/source.vb | Applied same API modernization changes as C# version |
snippets/csharp/System.Reflection.Emit/TypeBuilder/DefineMethodOverride/source.cs
Outdated
Show resolved
Hide resolved
…dOverride/source.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
This LGTM @gewarren
Let's ![]()
Problem
The code examples for
TypeBuilder.DefineMethodOverrideat https://learn.microsoft.com/en-us/dotnet/api/system.reflection.emit.typebuilder.definemethodoverride?view=net-9.0#examples were using .NET Framework-specific APIs that are not available in .NET Core, .NET 5+, or .NET 9. This made the examples non-compilable for modern .NET versions despite being displayed on the .NET 9 documentation page.Changes
Updated both C# and Visual Basic code examples to use modern .NET APIs:
C# Changes
Project.csprojto targetnet9.0(wasnet48) and changedOutputTypetoExeAppDomain.CurrentDomain.DefineDynamicAssembly()withAssemblyBuilder.DefineDynamicAssembly()(modern API pattern)AssemblyBuilderAccess.RunAndSavetoAssemblyBuilderAccess.Run(theRunAndSaveoption is not supported in .NET Core+)DefineDynamicModule(name, fileName)toDefineDynamicModule(name)to match the modern method signatureab.Save()call and related comment (assembly persistence is not supported in .NET Core+)Visual Basic Changes
Project.vbprojtargetingnet9.0withOutputTypeset toExeTesting
Both examples now:
DefineMethodOverridefunctionalityThe core functionality demonstrated by the examples (using
DefineMethodOverrideto associate a method body with an interface method declaration) remains unchanged and works identically on .NET 9.Fixes #[issue number]
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.