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
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
Description
Generated strongly typed WMI collection wrappers and their enumerators now implement
IDisposable. CallingDispose()releases the wrappedManagementObjectCollectionorManagementObjectEnumeratorand 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.GetStronglyTypedClassCodedid not implementIDisposable. A generated collection could not be used in ausingstatement, and consumers could not deterministically release the WMI resources held by its wrappedManagementObjectCollectionorManagementObjectEnumerator.New behavior
The generated collection and enumerator types implement
IDisposable. Consumers can dispose them to release the underlying WMI resources.Adding
IDisposableto these generated, non-sealed types can affect code that derives from a generated wrapper and already declares aDisposemember or implements its own disposal pattern.Type of breaking change
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
usingorusing var.If your code derives from a generated collection or enumerator wrapper and already defines a disposal pattern, review the generated type's new
IDisposableimplementation. Update the derived type to avoid conflictingDisposemembers 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 typesSystem.Management.ManagementClass.GetStronglyTypedClassCode(bool, bool)generated enumerator types