GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Make PowerShell Core enumerate COM collections by daxian-dbw · Pull Request #4553 · PowerShell/PowerShell

Conversation

@daxian-dbw

@daxian-dbw Dongbo Wang (daxian-dbw) commented Aug 11, 2017

Copy link
Copy Markdown
Member

Fix #3775

'GetEnumerator()' is not supported on COM collections in .NET Core (see https://github.com/dotnet/corefx/issues/19731), so we need to have our own implementation to enumerate COM collections.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Dongbo Wang (daxian-dbw) added 2 commits August 10, 2017 18:22
@daxian-dbw
Make PowerShell Core enumerate COM collections
15d6ce2
@daxian-dbw
Add tests
3ee11d8
@daxian-dbw Dongbo Wang (daxian-dbw) assigned Ilya (iSazonov) Aug 11, 2017
@daxian-dbw
Dongbo Wang (daxian-dbw) requested review from Aditya Patwardhan (adityapatwardhan) and Ilya (iSazonov) August 11, 2017 17:10
@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-not-required label Aug 11, 2017
@daxian-dbw
Skip COM tests on Unix
d49de32
lzybkr
Jason Shirk (lzybkr) previously approved these changes Aug 11, 2017
View reviewed changes
adityapatwardhan
Aditya Patwardhan (adityapatwardhan) reviewed Aug 11, 2017
View reviewed changes

@adityapatwardhan Aditya Patwardhan (adityapatwardhan) left a comment

Copy link
Copy Markdown
Member

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 with minor comment

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/System.Management.Automation/engine/COM/ComUtil.cs

return enumVariant != null ? new ComEnumerator(enumVariant) : null;
}
}

@adityapatwardhan Aditya Patwardhan (adityapatwardhan) Aug 11, 2017

Copy link
Copy Markdown
Member

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.

Add extra line at the end.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Aug 11, 2017

Copy link
Copy Markdown
Member Author

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.

Added a new line.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
adityapatwardhan
Aditya Patwardhan (adityapatwardhan) previously approved these changes Aug 11, 2017
View reviewed changes
Dongbo Wang (daxian-dbw) and others added 2 commits August 11, 2017 15:28
@daxian-dbw
Add a new line to the end of ComUtil.cs
4d6e365
@daxian-dbw
Fix failing test
3b53c0f
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Aug 11, 2017

Copy link
Copy Markdown
Member Author

I should use Measure-Object in the test but instead used Measure-Command, which pops for mandatory parameter input and thus caused the build to hang. It's fixed now.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iSazonov
Ilya (iSazonov) reviewed Aug 12, 2017
View reviewed changes
Comment thread src/System.Management.Automation/engine/COM/ComUtil.cs Outdated

internal static ComEnumerator Create(object comObject)
{
if (!comObject.GetType().IsCOMObject) { return null; }

@iSazonov Ilya (iSazonov) Aug 12, 2017

Copy link
Copy Markdown
Collaborator

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.

Should we check comObject != null ?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Aug 14, 2017

Copy link
Copy Markdown
Member Author

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.

Will add a null check here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Aug 15, 2017

Copy link
Copy Markdown
Collaborator

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.

Closed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/System.Management.Automation/engine/COM/ComUtil.cs Outdated
}
}

return enumVariant != null ? new ComEnumerator(enumVariant) : null;

@iSazonov Ilya (iSazonov) Aug 12, 2017

Copy link
Copy Markdown
Collaborator

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.

Maybe use else to exclude duplicate check with line 399?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Aug 14, 2017

Copy link
Copy Markdown
Member Author

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.

It's not a duplicate check, line 416 could make enumVariant not null or continue to be null.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Aug 15, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

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 meant that here slightly hidden logic. Maybe:

// if IEnumVARIANT interface
var enumVariant = comObject as COM.IEnumVARIANT;
if (enumVariant != null)
{
    return new ComEnumerator(enumVariant);
}

//  if  a collection
var enumerable = comObject as IEnumerable; 
...
    enumVariant = result as COM.IEnumVARIANT; 
    if (enumVariant != null)
    {
        return new ComEnumerator(enumVariant);
    }
...

return null;  // any warnings for users?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Aug 15, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

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.

This is more of a coding style rather than an issue that needs to be corrected.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Aug 15, 2017

Copy link
Copy Markdown
Member Author

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.

Wait, I see your point now -- there will be one more null check if the COM object is already an enum variant. Will update the code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Aug 15, 2017

Copy link
Copy Markdown
Member Author

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.

Code updated.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Aug 16, 2017

Copy link
Copy Markdown
Collaborator

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.

Thanks for understanding and sorry that I was unclear.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread test/powershell/engine/COM/COM.Basic.Tests.ps1 Outdated
Describe 'Basic COM Tests' -Tags "CI" {
It "Should enumerate ShellWindows" {
$shell = New-Object -ComObject "Shell.Application"
$windows = $shell.Windows()

@iSazonov Ilya (iSazonov) Aug 12, 2017

Copy link
Copy Markdown
Collaborator

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.

Is it work on Core and IoT?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Aug 14, 2017

Copy link
Copy Markdown
Member Author

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.

Good catch. NanoServer and IoT don't have the shell, so these tests don't apply. Will update.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@daxian-dbw
Address 2 more comments
5490f76
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Aug 14, 2017

Copy link
Copy Markdown
Member Author

Ilya (@iSazonov) I have addressed your comments. Please take another look. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov
Ilya (iSazonov) dismissed stale reviews from Jason Shirk (lzybkr) and Aditya Patwardhan (adityapatwardhan) August 15, 2017 05:34

We have new commits - please take another look.

@iSazonov

Ilya (iSazonov) commented Aug 15, 2017

Copy link
Copy Markdown
Collaborator

Jason Shirk (@lzybkr) Aditya Patwardhan (@adityapatwardhan) We have new commits - please take another look.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

adityapatwardhan
Aditya Patwardhan (adityapatwardhan) approved these changes Aug 15, 2017
View reviewed changes

@adityapatwardhan Aditya Patwardhan (adityapatwardhan) left a comment

Copy link
Copy Markdown
Member

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
iSazonov
Ilya (iSazonov) reviewed Aug 15, 2017
View reviewed changes
Comment thread src/System.Management.Automation/engine/COM/ComUtil.cs Outdated
}
}

return enumVariant != null ? new ComEnumerator(enumVariant) : null;

@iSazonov Ilya (iSazonov) Aug 15, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

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 meant that here slightly hidden logic. Maybe:

// if IEnumVARIANT interface
var enumVariant = comObject as COM.IEnumVARIANT;
if (enumVariant != null)
{
    return new ComEnumerator(enumVariant);
}

//  if  a collection
var enumerable = comObject as IEnumerable; 
...
    enumVariant = result as COM.IEnumVARIANT; 
    if (enumVariant != null)
    {
        return new ComEnumerator(enumVariant);
    }
...

return null;  // any warnings for users?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/System.Management.Automation/engine/COM/ComUtil.cs Outdated
}
catch (Exception)
{
/* Catch all exception. */

@iSazonov Ilya (iSazonov) Aug 15, 2017

Copy link
Copy Markdown
Collaborator

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.

Obvious comment and typo (exception -> exceptions). Catch all exceptions - why? Please enhance the comment or remove.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Aug 15, 2017

Copy link
Copy Markdown
Member Author

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.

Fixed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Dongbo Wang (daxian-dbw) added 3 commits August 15, 2017 09:19
@daxian-dbw
Add more comment for the catch-all-exception block
1d0ce46
@daxian-dbw
Add comment block for the method
50ae76c
@daxian-dbw
Address another comment and add one more test
864a58d
@daxian-dbw
Dongbo Wang (daxian-dbw) requested review from Bruce Payette (BrucePay), James Truher (JamesWTruher), Travis Plunk (TravisEz13) and sergei (vors) as code owners August 15, 2017 19:25
@daxian-dbw
Dongbo Wang (daxian-dbw) removed request for Bruce Payette (BrucePay) and sergei (vors) August 15, 2017 19:26
@daxian-dbw
Dongbo Wang (daxian-dbw) removed request for James Truher (JamesWTruher) and Travis Plunk (TravisEz13) August 15, 2017 19:26
iSazonov
Ilya (iSazonov) approved these changes Aug 16, 2017
View reviewed changes
@iSazonov

Ilya (iSazonov) commented Aug 16, 2017

Copy link
Copy Markdown
Collaborator

Jason Shirk (@lzybkr) Can you approve?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw

Dongbo Wang (daxian-dbw) commented Aug 16, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Ilya (@iSazonov) Jason probably doesn't have time to come back and approve it again, so it's up to the maintainer's judgment to see if it's necessary for reviewers who had approved to approve again. There are some guidelines you can use, for example:

  1. are the changes after the previous approval fundamental or just touch-ups
  2. are the changes to address comments left by the reviewer who previously approved

Certainly, you will get your own guidelines as you become more experienced in this role.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Aug 16, 2017

Copy link
Copy Markdown
Collaborator

Dongbo Wang (@daxian-dbw) Thank you for the helpful comment!

In this case, it's more of a courtesy - I have to show respect and ask him after I formally dismissed his approval.

daxian-dbw reacted with thumbs up emoji daxian-dbw reacted with laugh emoji
All reactions
  • 👍 1 reaction
  • 😄 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JamesWTruher
James Truher (JamesWTruher) reviewed Aug 16, 2017
View reviewed changes
Comment thread test/powershell/engine/COM/COM.Basic.Tests.ps1 Resolved

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw

Dongbo Wang (daxian-dbw) commented Aug 16, 2017

Copy link
Copy Markdown
Member Author

Ilya (@iSazonov) Another related comment. I usually don't dismiss a reviewer's approval unless the PR needs some fundamental changes (e.g. design flaw, logic changes and etc.). If the following-up changes are touch-ups or minor fixes (like typo, a null condition check, test fix-up), I think it's fine to keep the previous approval, and once the minor issues are addressed, you can approve the PR and merge it.

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw
Replace shell-windows tests with shell-folder tests
7a06a82
@iSazonov

Ilya (iSazonov) commented Aug 17, 2017

Copy link
Copy Markdown
Collaborator

Dongbo Wang (@daxian-dbw) I wonder why CI AppVeyor failed?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw
Minor change in test
459518d
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Aug 17, 2017

Copy link
Copy Markdown
Member Author

I have investigated the failure, it actually a bug in Binder, more specifically at here, the restriction generated in the call to this.DeferForPSObject doesn't respect the fact that the baseobject needs to be a COM object.

A repro would be:

$shell = New-Object -ComObject "Shell.Application"
$folder = $shell.Namespace("F:\tmp")
#$item = $folder.Items().Item(0)
$item = $folder.Items() | select -Last 1
$item.Name


$members = new-object System.Collections.ObjectModel.Collection[System.Management.Automation.PSMemberInfo]
$n=new-object Management.Automation.PSNoteProperty a,1
$members.Add($n)
$r=add-member -InputObject a -MemberType MemberSet -Name Name -Value $members -passthru
$r.Name.a

The $r.Name.a is supposed to return 1. If you run the lower part first then upper part, then all work fine.
This happens when a COM object is wrapped into a PSObject, which is the case when the COM object is returned from a pipeline, like the above repro code.

I cannot open an issue until this PR is merged because the repro requires enumerating a COM collection.
I have updated the test to not access Name member, so it would be good now. When I resolve the bug, I will update the COM basic test to keep accessing the Name member.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Aug 17, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

Dongbo Wang (@daxian-dbw) Maybe made two commits for code and tests before rebase and merge?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw

Dongbo Wang (daxian-dbw) commented Aug 17, 2017

Copy link
Copy Markdown
Member Author

Ilya (@iSazonov) Please just choose 'Squash and merge'. It's a simple fix and there is no need to keep history commits.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw

Dongbo Wang (daxian-dbw) commented Aug 17, 2017

Copy link
Copy Markdown
Member Author

A follow-up of the binder bug:
The issue repros without COM enumeration. #4607 opened to track it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov
Ilya (iSazonov) merged commit befc5f8 into PowerShell:master Aug 17, 2017
@iSazonov

Ilya (iSazonov) commented Aug 17, 2017

Copy link
Copy Markdown
Collaborator

Dongbo Wang (@daxian-dbw) Merged.
Great work! Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@daxian-dbw
Dongbo Wang (daxian-dbw) deleted the COM branch August 17, 2017 16:24
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Aug 17, 2017

Copy link
Copy Markdown
Member Author

Ilya (@iSazonov) Thank you for the review and good work as a maintainer 😄

Here are some of my experiences to choose among Squash and merge, Rebase and merge and Create a merge commit:

  1. number of meaningful commits (commits that are part of the PR work, or commits to address major comments that require non-trivial design/logic changes) is one thing to consider
  2. the complexity of the PR work is also something to consider.
  • Some PR may involve many commits, but the fix or feature work is not complex, in those cases, just Squash and merge.
  • Some PR may have clean history commits, but again, the fix/work is simple, in those cases, Squash and merge
  • A PR may be complex work, and the history is not clean -- complex work usually means a lot major changes during the review process -- in such case, choose create a merge commit to preserve the history even though it's not clean. Example: Native pipe #2450
  • A PR is non-trivial and the history is clean, then it's worthy to keep the history. In this case, consider using rebase and merge to keep the main branch history clean if the number of commits is not too many (~5/6). Otherwise, use create a merge commit.
  • A PR may contain more than 1 fix, in this case we usually should ask the author to break it into two PRs.

As you can see from the main branch history, most of time we use (and prefer to) squash and merge.

As for what is a simple/complex/non-trivial fix/work, it's hard to describe but you will have your judgement call as you gain more expeirences.

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@iSazonov

Ilya (iSazonov) commented Aug 17, 2017

Copy link
Copy Markdown
Collaborator

Dongbo Wang (@daxian-dbw) Thanks for sharing your experience!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Feb 7, 2020
Fix how COM objects are enumerated #11795
Merged
Code OK on V5.1 does not run on V7.0.0RC2 #11782
Closed
@daxian-dbw Dongbo Wang (daxian-dbw) mentioned this pull request Jul 23, 2020
Remove ComEnumerator as COM objects using IEnumerator is now supported in .NET 5 #13259
Merged
8 of 14 tasks
@iRon7 iRon7 mentioned this pull request Jun 24, 2023
ComObject Member-access enumeration #19854
Open
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@daxian-dbw @iSazonov
Make PowerShell Core enumerate COM collections (PowerShell#4553)
cc58456
Make PowerShell Core enumerate COM collections
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@adityapatwardhan Aditya Patwardhan (adityapatwardhan) adityapatwardhan approved these changes
@iSazonov Ilya (iSazonov) iSazonov approved these changes
+2 more reviewers
@JamesWTruher James Truher (JamesWTruher) JamesWTruher left review comments
@lzybkr Jason Shirk (lzybkr) lzybkr left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@iSazonov Ilya (iSazonov)

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@daxian-dbw @iSazonov @lzybkr @JamesWTruher @adityapatwardhan @msftclas
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.