Topshelf exception

左心房为你撑大大i 提交于 2020-01-04 04:32:46

问题


I'm using topshelf and I'm getting this exception when I try to use the "-i" option to install as a service.

Unable to cast object of type 'Magnum.CommandLineParser.SwitchElement' to type 'Magnum.CommandLineParser.IArgumentElement'.

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();
}

回答1:


The way we use TopShelf to install as a service is

program.exe service install

I believe this is the only way it's supported in the RC code. You can uninstall via

program.exe service uninstall



回答2:


Looks like when passing in -i that the parser is converting it to a type of SwitchElement. 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();
    }


来源:https://stackoverflow.com/questions/3290437/topshelf-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!