Type <class name> appears to be immutable, but no constructor found to accept values.
Hi guys, could someone help me with a werid issue about immutable class? I have a class looks like this:
As you can see I am using command line parser to create a command line tools. I can run debug output successfully but not with release output. The error is:
Unhandled exception. System.InvalidOperationException: Type SugonBMCMegarac.ScriptVerb appears to be immutable, but no constructor found to accept values.
at CommandLine.Core.InstanceBuilder.BuildImmutable[T](Type, Maybe1, IEnumerable1, IEnumerable1, List1)
at CommandLine.Core.InstanceBuilder.<>cDisplayClass1_0
1.<Build>b5()
at CommandLine.Core.InstanceBuilder.Build[T](Maybe1, Func3, IEnumerable1, StringComparer, Boolean, CultureInfo, Boolean, Boolean, Boolean, IEnumerable1)
at CommandLine.Parser.ParseArguments[T](IEnumerable
1)
at SugonBMCMegarac.Program.Main(String[])7 Replies
Try removing the constructor, the class is clearly mutable with only public setters as far as I can see.
HI Pobiega, thanks for your helping here.
Actually I tried it. Doesn't work 🥲
What is the IDE warning for DomainOrIP btw?
The other string props don't have any warnins
Just typo I think
Ok
No idea then, except making sure you are not running a previous build
The class is not immutable, so I don't know why the cli helper would say it is
Yeah, I also wonder about it. Since I am not using keyworkd "record", and I can run the debug output successfully, I think maybe the compiler do the magic for me by default....
Thanks anyway. I will try delete all the output and try again.
Hi guys, after some debug, I found it is not related with the feature "Immutable Class". It caused by CommandLine.Core.InstanceBuilder.BuildImmutable in package CommandLineParser.
It simply check the ScriptVerb.IsMutable to decide which build method should be call BuildImmutable or BuildMutable.
Need further investigation. Will take another time to finish it.
PS: I checked the repo of CommandLineParser, it seems stop update about 2 years.... The bugs user reported leaves there for a long time.
There are other, better, alternatives for CLI development
I personally really enjoy https://github.com/Tyrrrz/CliFx