Description
Using statements do not properly dispose of System.Management.ManagementBaseObject or System.Management.ManagementObject due to both classes defining new Dispose() methods that hide the base class method with new rather than overriding the virtual void Dispose(bool disposing) from System.ComponentModel.Component.
Reproduction Steps
using System.Management;
using (var mo = new ManagementObject()) {
} // step through with a debugger and observe that neither ManagementObject.Dispose() nor ManagementBaseObject.Dispose() are called, but only Componnet.Dispose()
Expected behavior
ManagementObject and ManagementBaseObject have disposal code called.
Actual behavior
Only Component has its disposal code called.
Regression?
No
Known Workarounds
Avoid using using statements with these classes and instead use a try/finally.
Configuration
.NET 9
Windows 10 Enterprise
x64
Other information
See also https://stackoverflow.com/a/11896367/9287029
Description
Using statements do not properly dispose of
System.Management.ManagementBaseObjectorSystem.Management.ManagementObjectdue to both classes defining newDispose()methods that hide the base class method withnewrather than overriding thevirtual void Dispose(bool disposing)fromSystem.ComponentModel.Component.Reproduction Steps
Expected behavior
ManagementObjectandManagementBaseObjecthave disposal code called.Actual behavior
Only
Componenthas its disposal code called.Regression?
No
Known Workarounds
Avoid using
usingstatements with these classes and instead use a try/finally.Configuration
.NET 9
Windows 10 Enterprise
x64
Other information
See also https://stackoverflow.com/a/11896367/9287029