Sugeshan Govindsamy
Sugeshan Govindsamy

Reputation: 61

dotNet Core 2 Console App - Error 1053: The service did not respond in a timely fashion

First off, apologies everyone. I know that there are multiple posts about this error. I have not found any links relating to dotNet Core 2. Please point me to them.

I have created a simple dotNet Core 2 Console App with just the Main Method. I am able to publish this app as a portable target runtime which creates the relevant DLL file in the output folder.

After creating the service successfully, the service is unable to start on my local machine and throws the error mentioned "Error 1053: The service did not respond to the start or control request in a timely fashion"

Here is my environment:

Microsoft Windows 8.1 Enterprise Visual Studio Professional 2017
Version 15.5.7 Microsoft .Net Framework Version 4.7.02558

Program.cs

class Program
{
    static void Main(string[] args)
    {
        var fileName = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "log.txt");

        File.AppendAllText(fileName, "Hello, I am starting" + "\n");

        Console.WriteLine(" _____________________________________________________________________________");
        Console.WriteLine("|                Test Console Application as a Service                        |");
        Console.WriteLine("|-----------------------------------------------------------------------------|");
        Console.WriteLine("|                Version      : 1.0.0                                         |");
        Console.WriteLine("|                Created by   : S. Govindsamy                                 |");
        Console.WriteLine("|                Created on   : 20 Mar 2018                                   |");
        Console.WriteLine("|                Last updated :                                               |");
        Console.WriteLine("|_____________________________________________________________________________|");
        Console.WriteLine("");
        Console.WriteLine("");
        Console.WriteLine($"dotNet Version: {Environment.Version}");
        Console.WriteLine(DateTime.Now.ToString("dd MMM yyyy HH:mm:ss") + "..Started");
        Console.WriteLine("Checking to see if this is working ... press any key to exit...");
        File.AppendAllText(fileName, "Hello, I have written text to console ..." + "\n");
        Console.ReadLine();

        File.AppendAllText(fileName, "Hello, I am ending now ..." + "\n");

    }
}

ConsoleApplication.csproj

   <Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeIdentifiers>win7-x64;win8-x64;win81-x64;win10-x64;osx-x64</RuntimeIdentifiers>
    <StartupObject>ConsoleApplicationService.Program</StartupObject>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
    <PackageReference Include="ServiceProcess.Helpers" Version="0.9.1.9" />
  </ItemGroup>

</Project>

Upvotes: 3

Views: 8614

Answers (2)

Sugeshan Govindsamy
Sugeshan Govindsamy

Reputation: 61

I managed to find a way to make this work and get my service to start. I followed the micro-services architecture library created by Peter Kottas which is definitely the way to go if your console application is code in dotNet Core 2.

Please see the link on GitHub: https://github.com/PeterKottas/DotNetCore.WindowsService

Upvotes: 1

Roman Svitukha
Roman Svitukha

Reputation: 1402

Make sure your service has Allow service to interact with desktop option is turned on. To turn this option on, follow these steps:

  1. In the Services tool, click the service that you want to start, and then click Properties.
  2. Right-click the Log On tab, and then click to select the Allow service to interact with desktop check box.
  3. Click OK to exit the Properties dialog box.

Upvotes: 1

Related Questions