1
votes

I am experimenting with gRpc and have it running. I am using .net core 3.1. C# . I am now attempting to install it as a windows service. The machine is Win 10 Pro x64 .

I added the line as instructed to run it as a windows service...

public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            //https://docs.microsoft.com/en-us/dotnet/architecture/grpc-for-wcf-developers/self-hosted

            .UseWindowsService() // Enable running as a Windows service

            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });

I publish to a folder (I never have used publish before) and voila... there is the publish folder. I go to that folder and run (AS ADMINISTRATOR) installutil. Yes it found the utility as i used the full path. That path is

"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe"

Is this correct version to run for .net core? Does that matter?

So I run installutil {full-path-to}\grpcservice1.exe

I get...

Exception occurred while initializing the installation: System.BadImageFormatException: Could not load file or assembly 'file:///....\GrpcService1\GrpcService1\bin\Debug\netcoreapp3.1\publish\GrpcService1.exe' or one of its dependencies. The module was expected to contain an assembly manifest..

I can't figure out what I am doing wrong.... Suggestions? I just following the example.

TIA

1
I have tried specifying x64 for the build. - Jeff

1 Answers

2
votes

installutil.exe looks for an Installer class marked with the RunInstallerAttribute set to true. It only works for Windows Services written with .NET Framework.

In the case of .NET Core, I'd recommend publishing your application and registering a new service using sc create/New-Service as you would in the case of any other executable.

There are also detailed docs in the .NET Core documentation in case you needed something more detailed.