Reputation: 61
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"
dotnet ConsoleApplicationService.dll
" from the command prompt, then the application runs as expected. I made sure that I opened up command prompt from the published folder and ran the following code:
sc create "myDev Console Service" binpath= "C:\inetpub\wwwroot\myDev.ConsoleApplicationService\ConsoleApplicationService.dll"
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
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
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:
Upvotes: 1