Я пытаюсь вызвать TfvcHttpClient.GetItemsAsync()
из скрипта Powershell:
$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)
Похоже на логику разрешения перегрузкиглючитМетод действительно перегружен, но есть только одна перегрузка с 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
, которые описывают перегруженные методы, содержат два массива - arguments
и conversionRanks
.Код ожидает, что они имеют одинаковую длину, но в первом есть 7 элементов, а во втором - 6.