Skip to content

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

Merged
merged 3 commits into from
Feb 10, 2020
Merged

Conversation

daxian-dbw
Copy link
Member

@daxian-dbw daxian-dbw commented Feb 7, 2020

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

@ghost ghost assigned adityapatwardhan Feb 7, 2020
@daxian-dbw daxian-dbw added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Feb 7, 2020
@daxian-dbw daxian-dbw added this to the GA-consider milestone Feb 7, 2020
$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
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?

Copy link
Member Author

@daxian-dbw daxian-dbw Feb 7, 2020

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
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
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

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

LGTM

@adityapatwardhan
Copy link
Member

@SteveL-MSFT please update your review

@adityapatwardhan adityapatwardhan merged commit 35c7b78 into PowerShell:master Feb 10, 2020
@daxian-dbw daxian-dbw deleted the com branch February 10, 2020 23:52
@TravisEz13 TravisEz13 modified the milestones: GA-consider, GA-approved, 7.0.0 Feb 11, 2020
adityapatwardhan pushed a commit to adityapatwardhan/PowerShell that referenced this pull request Feb 18, 2020
@ghost
Copy link

ghost commented Feb 21, 2020

🎉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