Skip to content

[Breaking change]: Generated WMI wrappers implement IDisposable #55779

Closed

Description

@jeffhandley

Description

Generated strongly typed WMI collection wrappers and their enumerators now implement IDisposable. Calling Dispose() releases the wrapped ManagementObjectCollection or ManagementObjectEnumerator and its COM-backed WMI resources deterministically.

For more information, see dotnet/runtime#132587.

Version

.NET 11 RC 2

Previous behavior

The collection and enumerator types emitted by ManagementClass.GetStronglyTypedClassCode did not implement IDisposable. A generated collection could not be used in a using statement, and consumers could not deterministically release the WMI resources held by its wrapped ManagementObjectCollection or ManagementObjectEnumerator.

// The generated ServiceCollection type did not implement IDisposable.
Service.ServiceCollection services = service.SelectAll();

New behavior

The generated collection and enumerator types implement IDisposable. Consumers can dispose them to release the underlying WMI resources.

using Service.ServiceCollection services = service.SelectAll();

foreach (Service item in services)
{
    // Use item.
}

Adding IDisposable to these generated, non-sealed types can affect code that derives from a generated wrapper and already declares a Dispose member or implements its own disposal pattern.

Type of breaking change

  • Binary incompatible: Existing binaries might encounter a breaking change in behavior, such as failure to load or execute, and if so, require recompilation.
  • Source incompatible: When recompiled using the new SDK or component or to target the new runtime, existing source code might require source changes to compile successfully.
  • Behavioral change: Existing binaries might behave differently at run time.

Reason for change

The generated wrappers hold COM-backed WMI resources. This change exposes disposal behavior already supported by the wrapped System.Management types so consumers can release those resources deterministically. The existing finalizer fallback of the wrapped types remains unchanged.

Recommended action

Dispose generated collection and enumerator wrappers when they are no longer needed, preferably with using or using var.

If your code derives from a generated collection or enumerator wrapper and already defines a disposal pattern, review the generated type's new IDisposable implementation. Update the derived type to avoid conflicting Dispose members and to preserve disposal of both its own resources and the base wrapper's resources.

Feature area

Core .NET libraries

Affected APIs

  • System.Management.ManagementClass.GetStronglyTypedClassCode(bool, bool) generated collection types
  • System.Management.ManagementClass.GetStronglyTypedClassCode(bool, bool) generated enumerator types

Associated WorkItem - 639996

Activity

  1. added
    breaking-change
    on Aug 29, 2026
  2. added
    🗺️ mapQUEST
    on Aug 31, 2026
  3. removed
    🗺️ mapQUEST
    on Aug 31, 2026
  4. added
    🗺️ reQUEST
    and removed
    ⌚ Not Triaged
    on Oct 21, 2026
  5. added
    🗺️ mapQUEST
    on Oct 21, 2026
  6. moved this from 🔖 Ready to 👀 In review in dotnet/docs October 2026 Sprint projecton Oct 21, 2026
  7. removed
    🗺️ mapQUEST
    on Oct 21, 2026
  8. added
    🗺️ mapQUEST
    on Oct 21, 2026
  9. removed
    🗺️ mapQUEST
    on Oct 21, 2026
  10. added
    📌 seQUESTered
    and removed
    🗺️ reQUEST
    on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

📌 seQUESTeredbreaking-change

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions