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
Code OK on V5.1 does not run on V7.0.0RC2 #11782
Comments
@SeeminglyScience Have you any thoughts? |
I am somewhat new to GitHub so I am not sure what you are expecting when you say "Have you any thoughts" My only thought at this time would be expecting it to work on PSV7* or there to be a better/alternative way to achieve the same result? |
@RG255 References like "@RG255" means contacting the owner of this name. So my question was for @SeeminglyScience who could share useful thoughts about the issue. |
@iSazonov Looks like PowerShell isn't able to determine that You can kinda see this by attempting to get the property |
So playing with it a bit, my guess is that this happens because if you query Not sure atm where this needs to be fixed though. Tested with this code, click to expandAdd-Type -TypeDefinition '
using System;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
namespace Testing
{
public class DispatchWrapper
{
private readonly IDispatch _real;
internal DispatchWrapper(IDispatch real) => _real = real;
public static DispatchWrapper Create(object obj) => new DispatchWrapper((IDispatch)obj);
public int GetTypeInfoCount(out int info) => _real.GetTypeInfoCount(out info);
public int GetTypeInfo(int iTInfo, int lcid, out ITypeInfo ppTInfo) => _real.GetTypeInfo(iTInfo, lcid, out ppTInfo);
public int GetIDsOfNames(Guid iid, string[] rgszNames, int cNames, int lcid, int[] rgDispId)
=> _real.GetIDsOfNames(iid, rgszNames, cNames, lcid, rgDispId);
public void Invoke(
int dispIdMember,
Guid iid,
int lcid,
INVOKEKIND wFlags,
DISPPARAMS[] paramArray,
out object pVarResult,
out EXCEPINFO pExcepInfo,
out uint puArgErr)
=> _real.Invoke(
dispIdMember,
iid,
lcid,
wFlags,
paramArray,
out pVarResult,
out pExcepInfo,
out puArgErr);
}
[Guid("00020400-0000-0000-c000-000000000046")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[ComImport]
internal interface IDispatch
{
[PreserveSig]
int GetTypeInfoCount(out int info);
[PreserveSig]
int GetTypeInfo(int iTInfo, int lcid, out ITypeInfo ppTInfo);
[PreserveSig]
int GetIDsOfNames(
[MarshalAs(UnmanagedType.LPStruct)] Guid iid,
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr)] string[] rgszNames,
int cNames,
int lcid,
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.I4)] [Out] int[] rgDispId);
void Invoke(
int dispIdMember,
[MarshalAs(UnmanagedType.LPStruct)] Guid iid,
int lcid,
INVOKEKIND wFlags,
[MarshalAs(UnmanagedType.LPArray)] [In] [Out] DISPPARAMS[] paramArray,
out object pVarResult,
out EXCEPINFO pExcepInfo,
out uint puArgErr);
}
}'
$group = 'Users'
$groupObj = [ADSI]"WinNT://./$group,group"
$membersObj = @($groupObj.psbase.Invoke('Members'))
$disp = [Testing.DispatchWrapper]::Create($membersObj[0])
$nullGuid = [activator]::CreateInstance([guid])
$enUS = [cultureinfo]::CurrentCulture.LCID
$namesToQuery = '_NewEnum', 'ppEnumerator'
$dispIds = [int[]]::new($namesToQuery.Length)
$hr = $disp.GetIDsOfNames($nullGuid, $namesToQuery, $namesToQuery.Length, $enUS, $dispIds)
'HResult: 0x{0:X}' -f $hr
for ($i = 0; $i -lt $namesToQuery.Length; $i++) {
'{0} ID: {1}' -f $namesToQuery[$i], $dispIds[$i]
} Should return:
|
Another update, here's the code that needs to change: PowerShell/src/System.Management.Automation/engine/COM/ComUtil.cs Lines 426 to 439 in e2f838e
It fails because Instead of (or in addition to) querying type info, it needs to directly invoke Example invoke using the above code in the $results = $null
$excep = [Activator]::CreateInstance([Runtime.InteropServices.ComTypes.EXCEPINFO])
$argErr = 0u;
$disp.Invoke(-4, $nullGuid, $enUS, 'INVOKE_PROPERTYGET', @(), [ref] $res, [ref] $excep, [ref] $argErr)
# yield
$results Which returns:
|
/cc @SteveL-MSFT I'm pretty sure I've seen quite a few folks on with similar issues on the PS slack. This might be the first issue for it here, but it's potentially very impactful for folks still using COM objects frequently (and who aren't super likely to be vocal here). If possible, it may be worth resolving before 7.0 GA. |
@SeeminglyScience Thanks for your investigations! |
Thanks @SeeminglyScience for analyzing the issue and pinpoint the cause ❤️ The However, for the COM object that can be cast to PR was submitted: #11795 |
🎉This issue was addressed in #11795, which has now been successfully released as Handy links: |
The code in the attached script runs OK on V5 but generates the following error on V7:
The script:
TestUserIngroup_1.zip
The text was updated successfully, but these errors were encountered: