这个问题的根本原因是什么?CSharpOptParse、XslTransform.Transform(...) 还是 NUnit?如果这个问题无法修复,我可以使用其他什么等效的库来代替它,这是积极支持的?
我正在使用CSharpOptParse的 1.0.1 版本,它最后一次修改是在 2005 年 2 月。
我有以下类(当然为本示例进行了简化)与 CSharpOptParse 一起使用:
public enum CommandType
{
Usage
}
public class Options
{
[OptDef(OptValType.Flag)]
[LongOptionName("help")]
[Description("Displays this help")]
public bool Help { get; set; }
public CommandType CommandType
{
get { return CommandType.Usage; }
}
}
这是一些复制问题的单元测试代码:
TextWriter output = Console.Out;
Options options = new Options { Help = true };
Parser p = ParserFactory.BuildParser(options);
p.Parse();
output.WriteLine("Usage: Console [--a]");
UsageBuilder builder = new UsageBuilder();
builder.BeginSection("Arguments:");
builder.AddOptions(p.GetOptionDefinitions()); //could the issue be created here?
builder.EndSection();
builder.ToText(output, OptStyle.Unix, true); //The problem occurs here
我是否有可能通过没有使用正确的部分设置 UsageBuilder 来导致问题?可能这可能会导致 xslt 文件出现问题???
当我运行该代码时,出现以下异常:
System.Xml.XPath.XPathException : Function 'ext:FormatText()' has failed.
----> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: startIndex
at MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator)
at System.Xml.Xsl.XsltOld.Processor.ValueOf(ActionFrame context, Int32 key)
at System.Xml.Xsl.XsltOld.ValueOfAction.Execute(Processor processor, ActionFrame frame)
at System.Xml.Xsl.XsltOld.ActionFrame.Execute(Processor processor)
at System.Xml.Xsl.XsltOld.Processor.Execute()
at System.Xml.Xsl.XsltOld.Processor.Execute(TextWriter writer)
at System.Xml.Xsl.XslTransform.Transform(XPathNavigator input, XsltArgumentList args, TextWriter output, XmlResolver resolver)
at System.Xml.Xsl.XslTransform.Transform(IXPathNavigable input, XsltArgumentList args, TextWriter output, XmlResolver resolver)
at CommandLine.OptParse.UsageBuilder.ToText(TextWriter writer, OptStyle optStyle, Boolean includeDefaultValues, Int32 maxColumns)
--TargetInvocationException
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at System.Xml.Xsl.XsltOld.XsltCompileContext.FuncExtension.Invoke(XsltContext xsltContext, Object[] args, XPathNavigator docContext)
at MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator)
--ArgumentOutOfRangeException
at System.String.LastIndexOfAny(Char[] anyOf, Int32 startIndex, Int32 count)
我不知道是什么导致了这个问题....最奇怪的部分是它只发生在我的 NUnit 测试中。当通过“Console.exe --help”调用此代码时,它运行良好,没有异常。我看不出 CSharpOptParse 有什么问题,所以这可能是 .NET 的 XslTransform 类或 NUnit 中的问题吗?
有没有其他人遇到过这个问题?有人对如何追踪问题或切换到更好的图书馆有任何建议吗?