streamdeck-tools icon indicating copy to clipboard operation
streamdeck-tools copied to clipboard

CommandLineParser throws when using streamdeck-tools in .NET 8

Open eXpl0it3r opened this issue 1 year ago • 2 comments

When I upgraded my plugin to .NET 8, the plugin fails to start and logs the following:

Unhandled Exception: System.InvalidOperationException: Type BarRaider.SdTools.Payloads.StreamDeckOptions appears to be immutable, but no constructor found to accept values.
   at CommandLine.Core.InstanceBuilder.BuildImmutable[T](Type, Maybe`1, IEnumerable`1, IEnumerable`1, List`1)
   at CommandLine.Core.InstanceBuilder.<>c__DisplayClass1_0`1.<Build>b__5()
   at CommandLine.Core.InstanceBuilder.Build[T](Maybe`1, Func`3, IEnumerable`1, StringComparer, Boolean, CultureInfo, Boolean, Boolean, Boolean, IEnumerable`1)
   at CommandLine.Parser.ParseArguments[T](IEnumerable`1)
   at BarRaider.SdTools.SDWrapper.Run(String[], PluginActionId[], IUpdateHandler)
   at Clockify.Program.Main(String[]) in D:\a\streamdeck-clockify\streamdeck-clockify\Clockify\Program.cs:line 9

Here's the relevant code:

using BarRaider.SdTools;

namespace Clockify;

public static class Program
{
    public static void Main(string[] args)
    {
        SDWrapper.Run(args);
    }
}

It seems like some behavior with immutable types changed in .NET 8 which causes failures. When sticking to .NET 6, I'm not running into this issue.

eXpl0it3r avatar Nov 21 '24 14:11 eXpl0it3r

I don't observe this issue

OpenByteDev avatar Jul 29 '25 21:07 OpenByteDev

I figured out the issue with this. It's because I publish a self-containered executable and enabled trimming.

The trimming doesn't see the dynamic usage of the options class and removes the constructor or similar methods, which leads to this error.

One workaround would be to mark certain types, so that they are not being trimmed.

[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(StreamDeckOptions))]

This may likely however also be something that should be done in commandlineparser, see also https://github.com/commandlineparser/commandline/issues/897#issuecomment-1670706102

eXpl0it3r avatar Oct 28 '25 10:10 eXpl0it3r