gpt4 book ai didi

.net - Powershell 4中的方法解析错误

转载 作者:行者123 更新时间:2023-12-02 23:53:21 24 4
gpt4 key购买 nike

我正在尝试从Powershell脚本调用TfvcHttpClient.GetItemsAsync():

$Full = [Microsoft.TeamFoundation.SourceControl.WebApi.VersionControlRecursionType]::Full
$None = [System.Threading.CancellationToken]::None
$Items = $Cli.GetItemsAsync($TFVCPath, $Full, $false, $null, $null, $None).GetAwaiter().GetResult()

在Powershell 4中,它会出错:
##[error]System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Management.Automation.Adapter.CompareOverloadCandidates(OverloadCandidate candidate1, OverloadCandidate candidate2, Object[] arguments)
at System.Management.Automation.Adapter.FindBestCandidate(IEnumerable`1 candidates, Object[] arguments)
at System.Management.Automation.Adapter.FindBestCandidate(IEnumerable`1 candidates, Object[] arguments, PSMethodInvocationConstraints invocationConstraints)
at System.Management.Automation.Adapter.FindBestMethod(MethodInformation[] methods, PSMethodInvocationConstraints invocationConstraints, Object[] arguments, String& errorId, String& errorMsg, Boolean& expandParamsOnBest)
at System.Management.Automation.Language.PSInvokeMemberBinder.InvokeDotNetMethod(DynamicMetaObject target, DynamicMetaObject[] args, BindingRestrictions restrictions, MethodInformation[] mi, Type errorExceptionType)
at System.Management.Automation.Language.PSInvokeMemberBinder.FallbackInvokeMember(DynamicMetaObject target, DynamicMetaObject[] args, DynamicMetaObject errorSuggestion)
at System.Dynamic.DynamicMetaObject.BindInvokeMember(InvokeMemberBinder binder, DynamicMetaObject[] args)
at System.Dynamic.DynamicMetaObjectBinder.Bind(Object[] args, ReadOnlyCollection`1 parameters, LabelTarget returnLabel)
at System.Runtime.CompilerServices.CallSiteBinder.BindCore[T](CallSite`1 site, Object[] args)
at System.Dynamic.UpdateDelegates.UpdateAndExecute7[T0,T1,T2,T3,T4,T5,T6,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
at System.Management.Automation.Interpreter.DynamicInstruction``8.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)

看起来,重载解决方案的逻辑是 buggy 。该方法的确是重载的,但是只有一个带有6个参数的重载。另外两个有7。

Powershell 4支持省略具有默认值的方法参数(只要它们是 null),因此重载解析逻辑仍然可能适用。但是,我的调用并不模糊-没有其他将 VersionControlRecursionType作为第二个参数的重载。

任何想法如何解决这个问题?也许有一种方法可以告诉Powershell调用特定的重载?

他们已经在PS5中修复了此问题,但仍然...

编辑:在干净的DLL上复制。这是DLL代码,再现了令人反感的方法签名:
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Microsoft.TeamFoundation.SourceControl.WebApi
{
public enum VersionControlRecursionType
{
None = 0, OneLevel = 1, OneLevelPlusNestedEmptyFolders = 4, Full = 120
}
public class TfvcItem { }
public class TfvcVersionDescriptor { }

public abstract class TfvcHttpClientBase
{
public TfvcHttpClientBase() { }

public virtual Task<List<TfvcItem>> GetItemsAsync(string project, string scopePath = null, VersionControlRecursionType? recursionLevel = null, bool? includeLinks = null, TfvcVersionDescriptor versionDescriptor = null, object userState = null, CancellationToken cancellationToken = default(CancellationToken))
{
return null;
}
public virtual Task<List<TfvcItem>> GetItemsAsync(Guid project, string scopePath = null, VersionControlRecursionType? recursionLevel = null, bool? includeLinks = null, TfvcVersionDescriptor versionDescriptor = null, object userState = null, CancellationToken cancellationToken = default(CancellationToken))
{
return null;
}
public virtual Task<List<TfvcItem>> GetItemsAsync(string scopePath = null, VersionControlRecursionType? recursionLevel = null, bool? includeLinks = null, TfvcVersionDescriptor versionDescriptor = null, object userState = null, CancellationToken cancellationToken = default(CancellationToken))
{
return null;
}
}


public class TfvcHttpClient : TfvcHttpClientBase
{
public TfvcHttpClient() { }
}
}

这是演示行为的Powershell:
Add-Type -Path "Foo.dll"
$Cli = New-Object Microsoft.TeamFoundation.SourceControl.WebApi.TfvcHttpClient
$Full = [Microsoft.TeamFoundation.SourceControl.WebApi.VersionControlRecursionType]::Full
$None = [System.Threading.CancellationToken]::None
$Items = $Cli.GetItemsAsync("", $Full, $false, $null, $null, $None)

我也在调试器中捕获了异常。令人反感的方法位于 System.Management.Automation.dll中。描述重载方法的 candidate参数包含两个数组- argumentsconversionRanks。代码期望它们具有相同的长度,但是前者有7个元素,后者有6个元素。

最佳答案

以GUID作为第一个参数的7参数方法重载不会以这种特定方式出错。 Powershell 4仍然存在方法解析错误:)

关于.net - Powershell 4中的方法解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52667533/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com