Skip to content

Background Service to early up and running #12501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hannespreishuber opened this issue Jul 24, 2019 · 3 comments
Closed

Background Service to early up and running #12501

hannespreishuber opened this issue Jul 24, 2019 · 3 comments
Labels
area-hosting Includes Hosting area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Milestone

Comments

@hannespreishuber
Copy link

hannespreishuber commented Jul 24, 2019

following code fails with NullReferenceException

 protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var path = Path.Combine(AppDomain.CurrentDomain.GetData("WWWBaseDirectory").ToString(),
                "wwwroot\\videos"); ;

the reason is (my guess) the pipeline is not configured

   public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            AppDomain.CurrentDomain.SetData("WWWBaseDirectory", env.ContentRootPath);

Cause

     services.AddHostedService<VideosWatcher>();

runs earlier

@davidfowl
Copy link
Member

@hannespreishuber Can you provide the actual error and call stack?

@davidfowl
Copy link
Member

Yes this was an intentional breaking change that was made #11437.

A couple of things you can do:

  • Inject the IHostEnvironment or IWebHostEnvironment into the VideosWatcher.
  • Add the hosted service in Program.cs after calling ConfigureWebHostDefaults

cc @Tratcher @anurse

@ghost
Copy link

ghost commented Nov 12, 2020

Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!

@ghost ghost closed this as completed Nov 12, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
@amcasey amcasey added the area-hosting Includes Hosting label Jun 1, 2023
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-hosting Includes Hosting area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

No branches or pull requests

6 participants