Doraku / DefaultDocumentation

Create a simple markdown documentation from the Visual Studio xml one.
MIT No Attribution
157 stars 26 forks source link

Command-line tool fails with "Sequence contains more than one matching element" #48

Closed maxweisel closed 3 years ago

maxweisel commented 3 years ago

I've just installed the command-line tool, and when I run it on a C# assembly built with Visual Studio 2019 I get the following:

defaultdocumentation.exe -a MyAssembly.dll -d MyAssembly.xml
Unhandled exception. System.InvalidOperationException: Sequence contains more than one matching element
   at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at CommandLine.Core.TypeLookup.FindTypeDescriptorAndSibling(String name, IEnumerable`1 specifications, StringComparer comparer)
   at CommandLine.Core.InstanceBuilder.<>c__DisplayClass0_0`1.<Build>b__9(String name)
   at CommandLine.Core.Switch.<>c__DisplayClass0_0.<Partition>b__0(Token t)
   at System.Linq.Enumerable.WhereArrayIterator`1.MoveNext()
   at System.Collections.Generic.HashSet`1.UnionWith(IEnumerable`1 other)
   at System.Collections.Generic.HashSet`1..ctor(IEnumerable`1 collection, IEqualityComparer`1 comparer)
   at CommandLine.Core.TokenPartitioner.Partition(IEnumerable`1 tokens, Func`2 typeLookup)
   at CommandLine.Core.InstanceBuilder.<>c__DisplayClass0_0`1.<Build>b__5()
   at CommandLine.Core.InstanceBuilder.Build[T](Maybe`1 factory, Func`3 tokenizer, IEnumerable`1 arguments, StringComparer nameComparer, Boolean ignoreValueCase, CultureInfo parsingCulture, Boolean autoHelp, Boolean autoVersion, IEnumerable`1 nonFatalErrors)
   at CommandLine.Parser.ParseArguments[T](IEnumerable`1 args)
   at DefaultDocumentation.Program.Main(String[] args) in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Console\Program.cs:line 23

Any idea what I could be missing here? The assembly and xml file are both valid.

Max

maxweisel commented 3 years ago

It seems the command-line tool doesn't support the short flags. If I use the explicit command-line flags, I can get a little farther, but now I get this:

defaultdocumentation.exe --AssemblyFilePath MyAssembly.dll
Unhandled exception. System.Exception: Error while writing documentation for MyAssembly.MyClass
 ---> System.InvalidCastException: Unable to cast object of type 'ICSharpCode.Decompiler.TypeSystem.ParameterizedType' to type 'ICSharpCode.Decompiler.TypeSystem.ITypeDefinition'.
   at DefaultDocumentation.Writer.MarkdownWriter.WriteInheritances(DocItem item) in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Common\Writer\MarkdownWriter.cs:line 403
   at DefaultDocumentation.Writer.MarkdownWriter.WriteItem(DocItem item) in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Common\Writer\MarkdownWriter.cs:line 537
   at DefaultDocumentation.Writer.MarkdownWriter.WritePage(DirectoryInfo directory, DocItem item) in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Common\Writer\MarkdownWriter.cs:line 607
   at DefaultDocumentation.Writer.DocItemWriter.Execute() in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Common\Writer\DocItemWriter.cs:line 121
   --- End of inner exception stack trace ---
   at DefaultDocumentation.Writer.DocItemWriter.Execute() in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Common\Writer\DocItemWriter.cs:line 125
   at DefaultDocumentation.Generator.Execute(Settings settings) in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Common\Generator.cs:line 7
   at DefaultDocumentation.Program.<>c.<Main>b__0_2(SettingsArgs a) in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Console\Program.cs:line 31
   at CommandLine.ParserResultExtensions.WithParsed[T](ParserResult`1 result, Action`1 action)
   at DefaultDocumentation.Program.Main(String[] args) in D:\a\DefaultDocumentation\DefaultDocumentation\source\DefaultDocumentation.Console\Program.cs:line 23
Doraku commented 3 years ago

That's weird, I can reproduce the issue with short flag, I will check why commandlineparser complains. The second error is something else. Can you share the code of the type MyAssembly.MyClass? There seems to be a derived type causing problem. Edit: looking closer it may actually be because of a type deriving from MyAssembly.MyClass.

Doraku commented 3 years ago

So I found the culprit for the first exception, I thought putting case insensitive parsing for the arguments would only apply to long name for some reason, and I was using lower and upper variant of the same character for different options. I changed the problematic short flags.

IggaF commented 3 years ago

It seems the command-line tool doesn't support the short flags. If I use the explicit command-line flags, I can get a little farther, but now I get this:


Unhandled exception. System.Exception: Error while writing documentation for MyAssembly.MyClass
 ---> System.InvalidCastException: Unable to cast object of type 'ICSharpCode.Decompiler.TypeSystem.ParameterizedType' to type 'ICSharpCode.Decompiler.TypeSystem.ITypeDefinition'.

I am also seeing this exception. It's source is in MarkdownWriter, at 'WriteInheritances' method: foreach (ITypeDefinition t in typeItem.Type.GetNonInterfaceBaseTypes().Where(t => t != typeItem.Type)) { _builder.Append(GetLink(item, t)).Append(" &#129106; "); } Cast to ITypeDefinition in first foreach seems to be incorrect. Maybe it should be changed to IType? From this: foreach (ITypeDefinition t in typeItem.Type.GetNonInterfaceBaseTypes().Where(t => t != typeItem.Type))

to this : foreach (IType t in typeItem.Type.GetNonInterfaceBaseTypes().Where(t => t != typeItem.Type))

Doraku commented 3 years ago

ah that's definitely it, pretty stupid of me I probably missed it during the big refactoring and I didn't hit this case with my projects >_> I will push the fix later today, thanks @IggaF

Doraku commented 3 years ago

@maxweisel @IggaF Could one of you try the latest ci version and see if it run correctly now with those fix? Or maybe the source you are running DefaultDocumentation on are public and I can try it myself?

IggaF commented 3 years ago

@Doraku Hi, Source is not public... And I'm using nuget only - not console

Doraku commented 3 years ago

There is also a preview version for the msbuild task, but I created an official version 0.7.3 with the fix anyway. Could you confirm that it fixes the problem please :)?

IggaF commented 3 years ago

@Doraku Hi, I've tested it - works :) Thanks a lot!