-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Fix how COM objects are enumerated #11795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
$group = [ADSI]"WinNT://./Users,Group" | ||
$members = $group.Invoke('Members') | ||
$names = $members | ForEach-Object { $_.GetType().InvokeMember('Name', 'GetProperty', $null, $_, $null) } | ||
$names | Should -Not -BeNullOrEmpty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any specific names we can validate against that are always expected for this COM object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess 'Authenticated Users' and 'INTERACTIVE'. Let me update and test it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@SteveL-MSFT please update your review |
🎉 Handy links: |
PR Summary
Fix #11782
The
ComEnumerator
was introduced back in early .NET Core 2.0 preview period of time (#4553), becauseGetEnumerator()
didn't work on COM object even if the object can be cast toIEnumerable
and .NET Core team said it was by design at the time (dotnet/runtime#21690).With .NET Core 3.1,
GetEnumerator()
works on the COM objects that can be cast toIEnumerable
🎉So we can directly use the .NET Core support to get the enumerator for a COM object that implements
IEnumerable
.However, for the COM object that can be cast to
IEnumerator
, exception is thrown when callingMoveNext()
on it.So we still need the
ComEnumerator
, but much simplified to just cover the case that the COM object implementsCOM.IEnumVARIANT
interface.PR Context
PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.