Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

560
Views
El servicio de Windows no se inicia: se registra una excepción

He visto algunas variantes de este problema, pero ninguna es exactamente igual a mi problema.

Estoy construyendo un Servicio de Windows, usando .NET 6.0. Este servicio aloja ASP.NET Core además de otras funciones en segundo plano. Cuando se ejecuta como una aplicación ordinaria, todo está bien, pero cuando se registra como un servicio, al iniciar falla con:

 Application: MyService.exe CoreCLR Version: 6.0.222.6406 .NET Version: 6.0.2 Description: The process was terminated due to an unhandled exception. Exception Info: System.NotSupportedException: The content root changed from "C:\WINDOWS\system32\" to "c:\long-path-executable\". Changing the host configuration using WebApplicationBuilder.Host is not supported. Use WebApplication.CreateBuilder(WebApplicationOptions) instead. at Microsoft.AspNetCore.Builder.ConfigureHostBuilder.ConfigureHostConfiguration(Action`1 configureDelegate) at Microsoft.Extensions.Hosting.HostingHostBuilderExtensions.UseContentRoot(IHostBuilder hostBuilder, String contentRoot) at Microsoft.Extensions.Hosting.WindowsServiceLifetimeHostBuilderExtensions.UseWindowsService(IHostBuilder hostBuilder, Action`1 configure) at Program.Main(String[] args) in C:\...\Program.cs:line 41

El mensaje de error es bastante específico: use WebApplication.Createbuilder. El problema es que eso es exactamente lo que ya estoy haciendo. Aquí está el código de inicio de mi programa:

 var builder = WebApplication.CreateBuilder(args); builder.Host.UseWindowsService(options => { options.ServiceName = "FileFlow"; }); builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); builder.Services.AddHostedService<WindowsService>(); var app = builder.Build(); if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseAuthorization(); app.MapControllers(); app.Run();

Como puede ver en el seguimiento de la pila, está fallando muy temprano en el proceso de compilación.

Sugerencias apreciadas. Mientras tanto, seguiré investigando.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esta otra publicación https://stackoverflow.com/a/70036550/4139809 tiene la respuesta:

 var builder = WebApplication.CreateBuilder(new WebApplicationOptions { Args = args, ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default });

Gracias a Jeremy Lakeman por señalar esa publicación en los comentarios.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!