Code OK on V5.1 does not run on V7.0.0RC2
See original GitHub issueName 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"}
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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), 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 (https://github.com/dotnet/runtime/issues/21690). With .NET Core 3.1,GetEnumerator()
works on the COM objects that can be cast toIEnumerable
🎉However, for the COM object that can be cast to
IEnumerator
, exception is thrown when callingMoveNext()
on it. So we still need theComEnumerator
, but much simplified to just cover the case where the COM object implementsCOM.IEnumVARIANT
interface.PR was submitted: #11795
@SeeminglyScience Thanks for your investigations! I think we need to have more tests for COM interactions.