title: An error occurred while accessing the Microsoft.Extensions.Hosting services when do first migrations
body: <p>I don't understand what wrong.
  I tried to make a simple crud in .net core mvc with a very simple model which has few fields.</p>
  <p>These are my models:</p>
  <pre><code>    public class Employee
      {
          [Key] public int EmployeeId { get; set; }
  
          [Required] public string FistName { get; set; }
  
          [Required] public string LastName { get; set; }
  
          public int PositionId { get; set; }
          public virtual Position Position { get; set; }
  
      }
  public class Position
      {
          [Key]
          public int PositionId { get; set; }
          public string PositionName { get; set; }
          public ICollection&lt;Employee&gt; Employees { get; set; }
      }
  </code></pre>
  <p>then I made app context:</p>
  <pre><code>public class EmployeeContext : DbContext
  {
      public EmployeeContext(DbContextOptions&lt;EmployeeContext&gt; options)
          : base(options)
      {
      }
  
      public DbSet&lt;Employee&gt; Employees { get; set; }
      public DbSet&lt;Position&gt; Positions { get; set; }
  
      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;Employee&gt;()
              .HasOne(e =&gt; e.Position)
              .WithMany()
              .HasForeignKey(e =&gt; e.PositionId);
      }
  }
  </code></pre>
  <p>and registered context in Startup.cs:</p>
  <pre><code> public void ConfigureServices(IServiceCollection services)
      {
          services.Configure&lt;CookiePolicyOptions&gt;(options =&gt;
          {
              // This lambda determines whether user consent for non-essential cookies is needed for a given request.
              options.CheckConsentNeeded = context =&gt; true;
              options.MinimumSameSitePolicy = SameSiteMode.None;
          });
  
          services.AddDbContext&lt;EmployeeContext&gt;(item =&gt;item.UseSqlServer(Configuration.GetConnectionString(&quot;DefaultConnection&quot;)));
  
  services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);                
          }
  </code></pre>
  <p>may be need one more file code of .csproj and program.cs</p>
  <pre><code>&lt;Project Sdk=&quot;Microsoft.NET.Sdk.Web&quot;&gt;
  
    &lt;PropertyGroup&gt;
      &lt;TargetFramework&gt;net461&lt;/TargetFramework&gt;
      &lt;DebugType&gt;full&lt;/DebugType&gt;
    &lt;/PropertyGroup&gt;
  
  
    &lt;ItemGroup&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore&quot; Version=&quot;2.2.0&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.CookiePolicy&quot; Version=&quot;2.2.8&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.Mvc&quot; Version=&quot;2.2.0&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.StaticFiles&quot; Version=&quot;2.2.0&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.EntityFrameworkCore&quot; Version=&quot;3.1.2&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.EntityFrameworkCore.Design&quot; Version=&quot;3.1.2&quot;&gt;
        &lt;PrivateAssets&gt;all&lt;/PrivateAssets&gt;
        &lt;IncludeAssets&gt;runtime; build; native; contentfiles; analyzers; buildtransitive&lt;/IncludeAssets&gt;
      &lt;/PackageReference&gt;
      &lt;PackageReference Include=&quot;Microsoft.EntityFrameworkCore.SqlServer&quot; Version=&quot;3.1.2&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.EntityFrameworkCore.SqlServer.Design&quot; Version=&quot;1.1.6&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.EntityFrameworkCore.Tools&quot; Version=&quot;3.1.2&quot;&gt;
        &lt;PrivateAssets&gt;all&lt;/PrivateAssets&gt;
        &lt;IncludeAssets&gt;runtime; build; native; contentfiles; analyzers; buildtransitive&lt;/IncludeAssets&gt;
      &lt;/PackageReference&gt;
      &lt;PackageReference Include=&quot;Microsoft.Extensions.Logging.Configuration&quot; Version=&quot;3.1.2&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.VisualStudio.Web.CodeGeneration.Design&quot; Version=&quot;3.1.1&quot; /&gt;
    &lt;/ItemGroup&gt;
  
  &lt;/Project&gt;
  
  public class Program
      {
          public static void Main(string[] args)
          {
              CreateWebHostBuilder(args).Build().Run();
          }
  
          public static IWebHostBuilder CreateWebHostBuilder(string[] args) =&gt;
              WebHost.CreateDefaultBuilder(args)
                  .UseStartup&lt;Startup&gt;();
      }
  </code></pre>
  <p>then I tried to do first migrate, but I see a very strange error
  Add-Migration FirstInit -verbose</p>
  <pre><code>Using project 'Crud'.
  Using startup project 'Crud'.
  Build started...
  Build succeeded.
  C:\.nuget\packages\microsoft.entityframeworkcore.tools\3.1.2\tools\net461\win-x86\ef.exe migrations add FirstInit --json --verbose --no-color --prefix-output --assembly C:\source\repos\Crud\Crud\bin\Debug\net461\Crud.exe --startup-assembly C:\source\repos\Crud\Crud\bin\Debug\net461\Crud.exe --project-dir C:\source\repos\Crud\Crud\ --language C# --working-dir C:\source\repos\Crud --root-namespace Crud
  Using assembly 'Crud'.
  Using startup assembly 'Crud'.
  Using application base 'C:\source\repos\Crud\Crud\bin\Debug\net461'.
  Using working directory 'C:\source\repos\Crud\Crud'.
  Using root namespace 'Crud'.
  Using project directory 'C:\source\repos\Crud\Crud\'.
  Using configuration file 'C:\source\repos\Crud\Crud\bin\Debug\net461\Crud.exe.config'.
  Using assembly 'Crud'.
  Using startup assembly 'Crud'.
  Using application base 'C:\source\repos\Crud\Crud\bin\Debug\net461'.
  Using working directory 'C:\source\repos\Crud\Crud'.
  Using root namespace 'Crud'.
  Using project directory 'C:\source\repos\Crud\Crud\'.
  Finding DbContext classes...
  Finding IDesignTimeDbContextFactory implementations...
  Finding application service provider...
  Finding Microsoft.Extensions.Hosting service provider...
  Using environment 'Development'.
  System.TypeLoadException: There is no implementation of the GetItem method in the type &quot;Microsoft.AspNetCore.Mvc.Razor.Internal.FileProviderRazorProjectFileSystem&quot; from assembly &quot;Microsoft.AspNetCore.Mvc.Razor, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60&quot;.
     в Microsoft.Extensions.DependencyInjection.MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngineServices(IServiceCollection services)
     в Microsoft.Extensions.DependencyInjection.MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(IMvcCoreBuilder builder)
     в Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddMvc(IServiceCollection services)
     в Crud.Startup.ConfigureServices(IServiceCollection services) в C:\source\repos\Crud\Crud\Startup.cs:строка 38
  --- End the stack trace from the previous location where the exception occurred ---
     в System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
     в Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
     в Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
     в Microsoft.AspNetCore.Hosting.Internal.WebHost.Initialize()
     в Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
  An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: There is no implementation of the GetItem method in the type &quot;Microsoft.AspNetCore.Mvc.Razor.Internal.FileProviderRazorProjectFileSystem&quot; from assembly &quot;Microsoft.AspNetCore.Mvc.Razor, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60&quot;.
  No application service provider was found.
  Finding DbContext classes in the project...
  Found DbContext 'EmployeeContext'.
  Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'EmployeeContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728 ---&gt; System.MissingMethodException:There are no parameterless constructors defined for this object..
     в System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor, Boolean&amp; bNeedSecurityCheck)
     в System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark)
     в System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark)
     в System.Activator.CreateInstance(Type type, Boolean nonPublic)
     в System.Activator.CreateInstance(Type type)
     в Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.&lt;&gt;c__DisplayClass13_3.&lt;FindContextTypes&gt;b__13()
     --- End trace of internal exception stack ---
     в Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.&lt;&gt;c__DisplayClass13_3.&lt;FindContextTypes&gt;b__13()
     в Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
     в Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
     в Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
     в Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
     в Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.&lt;&gt;c__DisplayClass0_0.&lt;.ctor&gt;b__0()
     в Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.&lt;&gt;c__DisplayClass3_0`1.&lt;Execute&gt;b__0()
     в Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
  Unable to create an object of type 'EmployeeContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
  </code></pre>
  <p>What's wrong with these 3 lines?</p>