這個問題的根本原因是什麼? CSharpOptParse,XslTransform.Transform(...)或NUnit?如果這個問題是不可修復的,那麼我可以使用什麼其他等效庫?僅當在NUnit測試中使用時,爲什麼CSharpOptParse UsageBuilder因XPathException而失敗?
我使用的CSharpOptParse 1.0.1版本,這是最後一次修改於2005年二月
我已經有下面的類(簡化當然這個例子中)與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中的問題?
是否有其他人遇到過這個問題?有沒有人有任何建議如何找出問題或切換到更好的圖書館?
我還沒有找到這個問題的答案......我不認爲我會得到很多的迴應,如果我把它賞金。有沒有人知道爲什麼會發生這種情況? – mezoid 2009-03-26 23:55:12