Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The name WebHost does not exists in current context

Tags:

I'm migrating from ASP.NET Core 1.x to v2.0 with the help of following post on docs.microsoft: https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/

I'm almost done with all the changes mentioned in that post. But there is one error that is causing troubles.

Here is my Program.cs file:

using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;

namespace MeridiaCoreAPI
{
    public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
           WebHost.CreateDefaultBuilder(args)
               .UseStartup<Startup>()
            .ConfigureAppConfiguration((hostContext, config) =>
            {
            // delete all default configuration providers
            config.Sources.Clear();
                config.AddJsonFile("myconfig.json", optional: true);
            })
               .Build();
    }
}

And here is the error message:

Suppression State
Error   CS0103  The name 'WebHost' does not exist in the current context

Any solution, workaround or hint would be highly appreciated. Thanks.

like image 385
Azaz ul Haq Avatar asked Nov 21 '17 15:11

Azaz ul Haq


1 Answers

WebHost class resides Microsoft.AspNetCore assembly that comes with Microsoft.AspNetCore.All NuGet package. So to fix you problem install this NuGet package and add following using directive to your source file:

using Microsoft.AspNetCore;

like image 62
CodeFuller Avatar answered Oct 17 '22 05:10

CodeFuller