Skip to content

Fix how COM objects are enumerated - #11795

Merged
Aditya Patwardhan (adityapatwardhan) merged 3 commits into
PowerShell:masterfrom
daxian-dbw:com
Feb 10, 2020
Merged

Aditya Patwardhan (adityapatwardhan) merged 3 commits into
PowerShell:masterfrom
daxian-dbw:com

Conversation

@daxian-dbw

@daxian-dbw Dongbo Wang (daxian-dbw) commented Feb 7, 2020 •

Copy link
Copy Markdown
Member

PR Summary

Fix #11782

The ComEnumerator was introduced back in early .NET Core 2.0 preview period of time (#4553), because GetEnumerator() didn't work on COM object even if the object can be cast to IEnumerable 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 to IEnumerable 🎉
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 calling MoveNext() on it.
So we still need the ComEnumerator, but much simplified to just cover the case that the COM object implements COM.IEnumVARIANT interface.

PR Context

PR Checklist

$group = [ADSI]"WinNT://./Users,Group"
$members = $group.Invoke('Members')
$names = $members | ForEach-Object { $_.GetType().InvokeMember('Name', 'GetProperty', $null, $_, $null) }
$names | Should -Not -BeNullOrEmpty

Copy link
Copy Markdown
Member

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?

@daxian-dbw Dongbo Wang (daxian-dbw) Feb 7, 2020 •

Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test updated.

@ghost ghost added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels Feb 7, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adityapatwardhan

Copy link
Copy Markdown
Member

Steve Lee (@SteveL-MSFT) please update your review

@ghost

Copy link
Copy Markdown

🎉v7.0.0-rc.3 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code OK on V5.1 does not run on V7.0.0RC2

6 participants