question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue
Name                           Value
----                           -----
PSVersion                      7.0.0-rc.2
PSEdition                      Core
GitCommitId                    7.0.0-rc.2
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

The code in the attached script runs OK on V5 but generates the following error on V7:

MethodInvocationException: S:\PowerShellScripts\TestUserIngroup_1.ps1:5
Line |
   5 |  … t -Process {$_.GetType().InvokeMember('Name', 'GetProperty', $null, $ …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "InvokeMember" with "5" argument(s): "Unknown name. (0x80020006 (DISP_E_UNKNOWNNAME))"

The script:

$user = $env:USERNAME
$group = 'Users'
$groupObj = [ADSI]"WinNT://./$group,group"
$membersObj = @($groupObj.psbase.Invoke('Members'))
$members = ($membersObj | ForEach-Object -Process {$_.GetType().InvokeMember('Name', 'GetProperty', $null, $_, $null)})

If ($members -contains $user) 
{Write-Host -Object "$user exists in the group $group"}
Else 
{Write-Host -Object "$user does not exists in the group $group"}

TestUserIngroup_1.zip

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
daxian-dbwcommented, Feb 7, 2020

Thanks @SeeminglyScience for analyzing the issue and pinpoint the cause ❤️

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 (https://github.com/dotnet/runtime/issues/21690). With .NET Core 3.1, GetEnumerator() works on the COM objects that can be cast to 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 where the COM object implements COM.IEnumVARIANT interface.

PR was submitted: #11795

2reactions
iSazonovcommented, Feb 6, 2020

@SeeminglyScience Thanks for your investigations! I think we need to have more tests for COM interactions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeLoadException is thrown when calling 'GetEnumerator ...
MoveNext(); // exception: Could not load type 'System.Runtime. ... Code OK on V5.1 does not run on V7.0.0RC2 PowerShell/PowerShell#11782.
Read more >
util/qht.c - Qemu source code (v5.0.0-rc2) - Bootlin
Assumptions: * - NULL cannot be inserted/removed as a pointer value. * - Trying to insert an already-existing hash-pointer pair is OK. However,...
Read more >
Makefile - Qemu source code (v8.0.3) - Bootlin
You can fix this by running \ "$(MAKE) distclean && rm -rf *-linux-user *-softmmu" in your source ... @exit 1 endif endif #...
Read more >
nextcloud-server/build at stable27
You can not select more than 25 topics Topics must start with a letter or number, can include ... dependabot/npm_and_yarn/nextcloud-vue-collections-0.11.1.
Read more >
Panic instead of ensure (#413) (3fa1ccc5) · Commits
Project 'parity/cumulus' was moved to 'parity/mirrors/cumulus'. Please update any links and bookmarks that may still have the old path.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found