locked
The type or namespace 'IWebHostEnvironment' could not be found. I already added the required namespace. RRS feed

  • Question

  • User206383436 posted

    Hi,

    I have been trying to use IWebHostEnvioronment instead of IHostingEnvironment. I have read several posts about how to fix this issue without success. What I have seen is that, supposedly, I only need to add the Microsoft.AspNetCore.Hosting namespace (and its reference of course which I've got from NuGet) and this would solve my trouble. I did this already but I am still facing the problem. The following code shows all the namespaces I reference in my class:

    using System;
    using System.Net;
    using System.Text.Json;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;
    using Microsoft.Extensions.Hosting;

    In the code blow, a red kind of line appears below the IWebHostEnvironment type for the env parameter saying that "The type or namespace 'IWebHostEnvironment' could not be found (are you missing a using directive or an assembly reference?)"

    public async Task Invoke(HttpContext context, IWebHostEnvironment env)
    {
        // Some code here.
    }

    I will very much appreciate yhour feedback.

    With respect,
    Jorge Maldonado

    Saturday, October 31, 2020 10:21 PM

Answers

All replies