Search code examples
asp.net-core.net-coreasp.net-core-3.0

'IHostingEnvironment' is obsolete


I updated my ASP.NET Core project to .NET Core v3.0.0-preview3, and I now get:

Startup.cs(75,50,75,69): warning CS0618: 'IHostingEnvironment' is obsolete: 'This type is obsolete and will be removed in a future version. The recommended alternative is Microsoft.AspNetCore.Hosting.IWebHostEnvironment.'

The code is:

public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
  if (env.IsDevelopment()) {
    …
  }
}

What is the correct way to do this now? Are there any documentation or examples to demonstrate that?


Solution

  • It seems IHostingEnvironment has been replaced by IHostEnvironment (and a few others). You should be able to change the interface type in your code and everything will work as it used to :-)

    You can find more information about the changes at this link on GitHub https://github.com/aspnet/AspNetCore/issues/7749

    There is also an additional interface IWebHostEnvironment that can be used in ASP.NET Core applications. This is available in the Microsoft.AspNetCore.Hosting namespace.