Topshelf exception

I use topshelf and I get this exception when I try to use the -i option to install as a service ... please help me ..

Cannot pass an object of type "Magnum.CommandLineParser.SwitchElement" to enter "Magnum.CommandLineParser.IArgumentElement".

An exception occurs in this function.

static void Set(TopshelfArguments args, IEnumerable<ICommandLineElement> commandLineElements) { var command = commandLineElements .Take(1) .Select(x => (IArgumentElement) x) //EXCEPTION BREAKS ON THIS LINE .Select(x => x.Id) .DefaultIfEmpty("commandline") .SingleOrDefault(); args.Command = command; //leftovers args.CommandArgs = commandLineElements.Skip(1).ToList(); } 

thanks

+3
source share
2 answers

How we use TopShelf for installation as a service,

 program.exe service install 

I believe this is the only way he supported in RC code. You can delete using

 program.exe service uninstall 
+3
source

It seems that when going into -i, the parser converts it to a SwitchElement type. Try this to see if it works.

 static void Set(TopshelfArguments args, IEnumerable<ICommandLineElement> commandLineElements) { var command = commandLineElements .Take(1) .Select(x => (ISwitchElement) x) .Select(x => x.Key) .DefaultIfEmpty("commandline") .SingleOrDefault(); args.Command = command; //leftovers args.CommandArgs = commandLineElements.Skip(1).ToList(); } 
+1
source

Source: https://habr.com/ru/post/1314631/


All Articles