Skip to content

Update samples#1363

Open
leculver wants to merge 1 commit intomicrosoft:mainfrom
leculver:sampls
Open

Update samples#1363
leculver wants to merge 1 commit intomicrosoft:mainfrom
leculver:sampls

Conversation

@leculver
Copy link
Contributor

Fixes #1272

This pull request updates the sample projects to modern .NET standards and refactors the code for improved clarity, null-safety, and maintainability. The most significant changes include migrating all sample projects to .NET 10, enabling nullable reference types and implicit usings, updating package references, and refactoring code to use newer APIs and patterns. Additionally, there are notable simplifications and improvements in the sample logic, especially around object/heap enumeration and argument handling.

Project and SDK Modernization:

  • All sample projects (ClrStack, DumpDict, DumpHeap, DbgEngExtension, DbgEngStandalone) are updated to target net10.0, with <ImplicitUsings>enable</ImplicitUsings> and <Nullable>enable</Nullable> for improved code safety and conciseness. [1] [2] [3]
  • Package references for Microsoft.Diagnostics.Runtime are replaced with project references to the local source, ensuring consistent builds and easier local development.

Code Quality and Null-Safety Improvements:

  • The code in ClrStack.cs, DumpDict.cs, and DumpHeap.cs is refactored to use nullable reference types, explicit null checks, and modern C# idioms. This includes using string?, is null, and null-forgiving operators, as well as removing unnecessary methods and comments. [1] [2] [3] [4] [5] [6] [7]

Sample Logic and API Updates:

  • In DumpDict, the logic is updated to correctly parse arguments, use the correct field name (_entries), and handle object validation and type checks more robustly. The sample now returns exit codes instead of calling Environment.Exit.
  • In DumpHeap, the object enumeration and statistics collection now handle possible null Type properties, preventing potential runtime exceptions.
  • In ClrStack, argument parsing and usage reporting are simplified, and exception handling is improved by using more specific exception types. [1] [2] [3] [4]

DbgEngExtension Refactoring:

  • The MAddress.cs logic for enumerating CLR memory addresses is refactored to use the new EnumerateClrNativeHeaps API, removing manual traversal of app domain heaps and stub heaps, and eliminating direct dependencies on DacInterface. This results in cleaner, more maintainable code. [1] [2] [3]

These changes collectively modernize the samples, improve code safety, and leverage the latest APIs for better maintainability and developer experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Building the ClrMd Samples

1 participant

Comments