Skip to content

Error when using C# PublishTrimmed, Trimmer can remove Types and Properties that spectre.console expects the type to have. (ExceptionFormatter) #1401

@rafaelsc

Description

@rafaelsc

Information

  • OS: Windows 10
  • Version: 0.48.0
  • Terminal: Any
  • Runtime: NET 8 with Publish Trimmed

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
I Tried without success creating a standalone minimal console app to reproduce, but look like trimmer is not removing the same types/properties in the same way in my application.

  • Create a new Console Application with NET8, with PublishTrimmed, SelfContained, PublishSingleFile, PublishReadyToRun.
  • Use ExceptionFormatter with a Exception with a stack trace.
  • ExceptionFormatter can some times throw a System.NullReferenceException when using reflection.
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Spectre.Console.ExceptionFormatter.TryGetTupleName(ParameterInfo parameter, Type parameterType, String& tupleName) in /_/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs:line 314
   at Spectre.Console.ExceptionFormatter.GetParameterName(ParameterInfo parameter) in /_/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs:line 280
   at Spectre.Console.ExceptionFormatter.GetStackFrames(Exception ex, ExceptionSettings settings) in /_/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs:line 79
   at Spectre.Console.ExceptionFormatter.GetException(Exception exception, ExceptionSettings settings) in /_/src/Spectre.Console/Widgets/Exceptions/ExceptionFormatter.cs:line 22
   at Program.<>c__DisplayClass0_1.<<Main>$>b__0(LiveDisplayContext ctx)
   at Spectre.Console.LiveDisplay.<>c__DisplayClass15_0.<Start>b__0(LiveDisplayContext ctx) in /_/src/Spectre.Console/Live/LiveDisplay.cs:line 47
   at Spectre.Console.LiveDisplay.<>c__DisplayClass17_0.<<StartAsync>b__0>d.MoveNext() in /_/src/Spectre.Console/Live/LiveDisplay.cs:line 80
--- End of stack trace from previous location ---
   at Spectre.Console.LiveDisplay.<>c__DisplayClass18_0`1.<<StartAsync>b__0>d.MoveNext() in /_/src/Spectre.Console/Live/LiveDisplay.cs:line 110
--- End of stack trace from previous location ---
   at Spectre.Console.Internal.DefaultExclusivityMode.RunAsync[T](Func`1 func) in /_/src/Spectre.Console/Internal/DefaultExclusivityMode.cs:line 40
   at Spectre.Console.LiveDisplay.StartAsync[T](Func`2 func) in /_/src/Spectre.Console/Live/LiveDisplay.cs:line 98
   at Spectre.Console.LiveDisplay.StartAsync(Func`2 func) in /_/src/Spectre.Console/Live/LiveDisplay.cs:line 78
   at Spectre.Console.LiveDisplay.Start(Action`1 action) in /_/src/Spectre.Console/Live/LiveDisplay.cs:line 51
   at Program.<Main>$(String[] args)

Expected behavior

  • No Exception when Formation a Exception.

Screenshots
image


Please upvote 👍 this issue if you are interested in it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions