rubberduck203 / GitNStats

Cross Platform Git History Analyzer built on .Net Core
MIT License
36 stars 3 forks source link

gitnstats --help does not work on Windows 10 #27

Closed efox29 closed 3 years ago

efox29 commented 3 years ago

When running the command gitnstats --help I get an error.

$ gitnstats --help
Unhandled exception. System.InvalidCastException: Specified cast is not valid.
   at CommandLine.Core.ReflectionExtensions.<>c.<GetUsageData>b__2_3(<>f__AnonymousType1`2 <>h__TransparentIdentifier0)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at CommandLine.Core.ReflectionExtensions.GetUsageData(Type type)
   at CommandLine.Text.HelpText.GetUsageFromType(Type type)
   at CommandLine.Text.HelpText.RenderUsageTextAsLines[T](ParserResult`1 parserResult, Func`2 mapperFunc)+MoveNext()
   at CSharpx.EnumerableExtensions.ToMaybe[T](IEnumerable`1 source)
   at CommandLine.Text.HelpText.AutoBuild[T](ParserResult`1 parserResult, Func`2 onError, Func`2 onExample, Boolean verbsIndex, Int32 maxDisplayWidth)
   at CommandLine.Text.HelpText.AutoBuild[T](ParserResult`1 parserResult, Func`2 onError, Int32 maxDisplayWidth)
   at CommandLine.Text.HelpText.AutoBuild[T](ParserResult`1 parserResult, Int32 maxDisplayWidth)
   at CommandLine.Parser.<>c__DisplayClass17_0`1.<DisplayHelp>b__1(IEnumerable`1 _, TextWriter writer)
   at CSharpx.MaybeExtensions.Do[T1,T2](Maybe`1 maybe, Action`2 action)
   at CommandLine.Parser.<>c__DisplayClass17_0`1.<DisplayHelp>b__0(IEnumerable`1 errors)
   at CommandLine.ParserResultExtensions.WithNotParsed[T](ParserResult`1 result, Action`1 action)
   at CommandLine.Parser.DisplayHelp[T](ParserResult`1 parserResult, TextWriter helpWriter, Int32 maxDisplayWidth)
   at CommandLine.Parser.MakeParserResult[T](ParserResult`1 parserResult, ParserSettings settings)
   at CommandLine.Parser.ParseArguments[T](IEnumerable`1 args)
   at GitNStats.Program.Main(String[] args)
rubberduck203 commented 3 years ago

Thanks for reporting this! I’ll have to set up a VM or something to test this.

rubberduck203 commented 3 years ago

I've just verified that this is a regression introduced in v2.3.0. I suspect it has something to do with the reflection that the CommandLine library is doing and the executable trimming I introduced. A plain .net 5.0 build without trimming should be enough to know for certain. If it's still doing it without trimming, it occurred during the 5.0 upgrade.

rubberduck203 commented 3 years ago

I think this is where we’re blowing up. https://github.com/commandlineparser/commandline/blob/d443a51aeb3a418425e970542b3b96e9da5f62e2/src/CommandLine/Core/ReflectionExtensions.cs#L44

UsageAttribute is defined here. I need to see if the whole lib is a single assembly. https://github.com/commandlineparser/commandline/blob/d443a51aeb3a418425e970542b3b96e9da5f62e2/src/CommandLine/Text/UsageAttribute.cs#L12

rubberduck203 commented 3 years ago

Ok. I was wrong about the trimming. I just reproduced this on MacOS before trimming the assembly. This appears to be related to switching to nullable reference types.

$ dotnet run --project src/gitnstats/gitnstats.csproj -- --help
Unhandled exception. System.InvalidCastException: Unable to cast object of type 'System.Runtime.CompilerServices.NullableAttribute' to type 'CommandLine.Text.UsageAttribute'.
   at CommandLine.Core.ReflectionExtensions.<>c.<GetUsageData>b__2_3(<>f__AnonymousType1`2 <>h__TransparentIdentifier0)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at CommandLine.Core.ReflectionExtensions.GetUsageData(Type type)
   at CommandLine.Text.HelpText.GetUsageFromType(Type type)
   at CommandLine.Text.HelpText.RenderUsageTextAsLines[T](ParserResult`1 parserResult, Func`2 mapperFunc)+MoveNext()
   at CSharpx.EnumerableExtensions.ToMaybe[T](IEnumerable`1 source)
   at CommandLine.Text.HelpText.AutoBuild[T](ParserResult`1 parserResult, Func`2 onError, Func`2 onExample, Boolean verbsIndex, Int32 maxDisplayWidth)
   at CommandLine.Text.HelpText.AutoBuild[T](ParserResult`1 parserResult, Func`2 onError, Int32 maxDisplayWidth)
   at CommandLine.Text.HelpText.AutoBuild[T](ParserResult`1 parserResult, Int32 maxDisplayWidth)
   at CommandLine.Parser.<>c__DisplayClass17_0`1.<DisplayHelp>b__1(IEnumerable`1 _, TextWriter writer)
   at CSharpx.MaybeExtensions.Do[T1,T2](Maybe`1 maybe, Action`2 action)
   at CommandLine.Parser.<>c__DisplayClass17_0`1.<DisplayHelp>b__0(IEnumerable`1 errors)
   at CommandLine.ParserResultExtensions.WithNotParsed[T](ParserResult`1 result, Action`1 action)
   at CommandLine.Parser.DisplayHelp[T](ParserResult`1 parserResult, TextWriter helpWriter, Int32 maxDisplayWidth)
   at CommandLine.Parser.MakeParserResult[T](ParserResult`1 parserResult, ParserSettings settings)
   at CommandLine.Parser.ParseArguments[T](IEnumerable`1 args)
   at GitNStats.Program.Main(String[] args) in /Users/rubberduck/src/GitNStats/src/gitnstats/Program.cs:line 11
rubberduck203 commented 3 years ago

This is due to a bug in a library I'm using to do command line parsing. It's incompatible with nullable reference types. I submitted a PR upstream to fix it. Once a new version of the library is released, I will update GitNStats and release a bug fix version.

https://github.com/commandlineparser/commandline/pull/715

rubberduck203 commented 3 years ago

@efox29 I just released a new version with a bug fix in place. https://github.com/rubberduck203/GitNStats/releases/tag/2.3.1

efox29 commented 3 years ago

Fix works on Windows 10.