code_junkie

Why is CSharpOptParse UsageBuilder failing due to an XPathException only when used in an NUnit test

Nov 13th, 2011
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. public enum CommandType
  2. {
  3. Usage
  4. }
  5.  
  6. public class Options
  7. {
  8. [OptDef(OptValType.Flag)]
  9. [LongOptionName("help")]
  10. [Description("Displays this help")]
  11. public bool Help { get; set; }
  12.  
  13. public CommandType CommandType
  14. {
  15. get { return CommandType.Usage; }
  16. }
  17. }
  18.  
  19. TextWriter output = Console.Out;
  20.  
  21. Options options = new Options { Help = true };
  22. Parser p = ParserFactory.BuildParser(options);
  23. p.Parse();
  24.  
  25. output.WriteLine("Usage: Oasis.Console [--a]");
  26. UsageBuilder builder = new UsageBuilder();
  27. builder.BeginSection("Arguments:");
  28. builder.AddOptions(p.GetOptionDefinitions()); //could the issue be created here?
  29. builder.EndSection();
  30. builder.ToText(output, OptStyle.Unix, true); //The problem occurs here
  31.  
  32. System.Xml.XPath.XPathException : Function 'ext:FormatText()' has failed.
  33. ----> System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  34. ----> System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection.
  35. Parameter name: startIndex
  36. at MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator)
  37. at System.Xml.Xsl.XsltOld.Processor.ValueOf(ActionFrame context, Int32 key)
  38. at System.Xml.Xsl.XsltOld.ValueOfAction.Execute(Processor processor, ActionFrame frame)
  39. at System.Xml.Xsl.XsltOld.ActionFrame.Execute(Processor processor)
  40. at System.Xml.Xsl.XsltOld.Processor.Execute()
  41. at System.Xml.Xsl.XsltOld.Processor.Execute(TextWriter writer)
  42. at System.Xml.Xsl.XslTransform.Transform(XPathNavigator input, XsltArgumentList args, TextWriter output, XmlResolver resolver)
  43. at System.Xml.Xsl.XslTransform.Transform(IXPathNavigable input, XsltArgumentList args, TextWriter output, XmlResolver resolver)
  44. at CommandLine.OptParse.UsageBuilder.ToText(TextWriter writer, OptStyle optStyle, Boolean includeDefaultValues, Int32 maxColumns)
  45. --TargetInvocationException
  46. at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
  47. at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
  48. at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
  49. at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
  50. at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
  51. at System.Xml.Xsl.XsltOld.XsltCompileContext.FuncExtension.Invoke(XsltContext xsltContext, Object[] args, XPathNavigator docContext)
  52. at MS.Internal.Xml.XPath.FunctionQuery.Evaluate(XPathNodeIterator nodeIterator)
  53. --ArgumentOutOfRangeException
  54. at System.String.LastIndexOfAny(Char[] anyOf, Int32 startIndex, Int32 count)
  55.  
  56. public TextTransformHelper(int maxColumns)
  57. {
  58. _maxColumns = maxColumns;
  59.  
  60. if (_maxColumns == -1)
  61. {
  62. // try to determine console width
  63. string os = Environment.GetEnvironmentVariable("OS");
  64.  
  65. if (os != null && os.StartsWith("Win"))
  66. {
  67. ConsoleUtils.ConsoleHelper ch = new ConsoleUtils.ConsoleHelper();
  68. _maxColumns = ch.GetScreenInfo().Size.X;
  69. }
  70. }
  71. }
  72.  
  73. public TextTransformHelper(int maxColumns)
  74. {
  75. _maxColumns = maxColumns;
  76.  
  77. if (_maxColumns == -1)
  78. {
  79. // try to determine console width
  80. string os = Environment.GetEnvironmentVariable("OS");
  81.  
  82. if (os != null && os.StartsWith("Win"))
  83. {
  84. ConsoleUtils.ConsoleHelper ch = new ConsoleUtils.ConsoleHelper();
  85. _maxColumns = ch.GetScreenInfo().Size.X;
  86. if(_maxColumns == 0) //added
  87. _maxColumns = -1; //added
  88. }
  89. }
  90. }
  91.  
  92. if (_maxColumns == -1)
  93. {
  94. output.Append((first) ? indentStr : handingIndentStr);
  95. output.Append(line);
  96. output.Append(Environment.NewLine);
  97. first = false;
  98. continue;
  99. }
Add Comment
Please, Sign In to add comment