What problem does it solve?
Migrating MSBuild's COM interop away from [ComImport] and built-in marshalling to AOT-compatible, struct-based CsWin32 patterns requires precise knowledge of vtable layouts, lifetime management, and error-handling parity that is easy to get wrong.
Core Features & Use Cases
- Manual COM struct definitions: Guides defining interfaces not in Win32 metadata (WMI IWbemLocator, Fusion IAssemblyCache, Setup Configuration) with correct
delegate* unmanaged[Stdcall] vtable slots and dual-target IComIID shapes for net472 and .NET.
- Lifetime management patterns: Enforces
ComScope<T> for transient pointers, using BSTR for COM strings, and AgileComPointer<T> for pointers stored in class fields, preventing leaks and apartment-agility hazards.
- Error-handling parity and test mocking: Preserves throw-vs-return contracts when migrating from
[ComImport], and bridges managed mocks to struct-based COM via CCW pointers from Marshal.GetComInterfaceForObject.
- Use Case: When adding WMI-based queries to MSBuild tasks, use this Skill to define the IWbemLocator/IWbemServices structs, activate them via
ComClassFactory.TryCreate, and scope every pointer correctly.
Quick Start
Ask the assistant to define a manual CsWin32 COM struct for the WMI IWbemLocator interface with proper ComScope lifetime handling and AOT-compatible activation.