无法加载类型ServiceCollectionExtensions

伊曼纽尔·维尔加斯(Emmanuel villegas)

我正在使用ASP.NET Core 1.0,并尝试为迁移配置DbContext。我有这个例外:

无法从程序集“ Microsoft.Extensions.DependencyInjection.Abstractions,版本= 1.0.0.0,文化=中性,PublicKeyToken = adb9793829ddae60”中加载类型“ Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionExtensions”。

我不确定为什么会收到此错误。有人知道我在想什么吗?

project.json

{
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.EntityFrameworkCore.Design": {
      "type": "build",
      "version": "1.0.0-preview2-final"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview1-final",
  },

  "tools": {
    "BundlerMinifier.Core": "2.0.238",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

Startup.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using OdeToFood.Services;
using OdeToFood.Entities;
using Microsoft.EntityFrameworkCore;

namespace OdeToFood
{
    public class Startup
    {
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                .AddEnvironmentVariables();

            if (env.IsDevelopment())
            {
                // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
                builder.AddApplicationInsightsSettings(developerMode: true);
            }
            Configuration = builder.Build();
        }

        public IConfigurationRoot Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.

            services.AddMvc();

            services.AddEntityFrameworkSqlServer()
                .AddDbContext<OdeToFoodDbContext>(options => options.UseSqlServer("@Server = (localdb)\\MSSQLLocalDB; Database = OdeToFood; Trusted_Connection = True; MultipleActiveResultSets = true"));
            services.AddSingleton(provider => Configuration);
            services.AddApplicationInsightsTelemetry(Configuration);
            services.AddScoped<IRestaurantData, InMemoryRestaurantData> ();

        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            app.UseApplicationInsightsRequestTelemetry();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseApplicationInsightsExceptionTelemetry();

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}

dbContext.cs

using Microsoft.EntityFrameworkCore;

namespace OdeToFood.Entities
{
    public class OdeToFoodDbContext:DbContext
    {
        public DbSet<Restaurant> Restaurants { get; set; }

        //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        //{
        //    optionsBuilder.UseSqlServer("@Server = (localdb)\\MSSQLLocalDB; Database = OdeToFood; Trusted_Connection = True; MultipleActiveResultSets = true");
        //}
    }
}
内特·巴贝蒂尼(Nate Barbettini)

您的project.json引用了此程序包的旧版本:

"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final"

它应该是:

"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0"

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

迁移应用程序时无法加载类型'Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions'

来自分类Dev

CodeBehind 无法加载类型

来自分类Dev

无法加载类型提交symfony 3

来自分类Dev

无法加载类型“ WebApplication1.SiteMaster”

来自分类Dev

Glide无法加载此类型的网址图片

来自分类Dev

无法加载类型ASP.ViewSwitcher

来自分类Dev

无法加载类型“ test.request”

来自分类Dev

Symfony Crud Edict:无法加载类型“ datetime”

来自分类Dev

CSS无法加载错误的MIME类型Django

来自分类Dev

F#TypeProvider无法加载类型

来自分类Dev

Symfony2无法加载类型EntityType

来自分类Dev

无法使用Azure signalR加载类型MessagePack

来自分类Dev

Glide无法加载此类型的网址图片

来自分类Dev

无法加载类型“ WebApplication1.SiteMaster”

来自分类Dev

无法加载类型“ Gregwar \ CaptchaBundle \ Type \ CaptchaType”

来自分类Dev

IIS错误:无法加载类型“ IsapiModule”

来自分类Dev

无法加载类型“Doctrine\DBAL\Types\TextType”

来自分类Dev

Symfony 3-无法加载类型表单类型

来自分类Dev

“无效的Resx文件,无法加载类型(类型)”不断返回

来自分类Dev

无法从程序集“System.Drawing, Version=4.0.0.0”的加载类型“System.Drawing.Font”加载类型

来自分类Dev

“无法加载类型<Namespace>。<Module>”是什么意思?

来自分类Dev

无法加载类型'Common.Logging.Factory.AbstractCachingLoggerFactoryAdapter'

来自分类Dev

无法加载类型'System.ComponentModel.DataAnnotations.Schema.IndexAttribute'

来自分类Dev

Activator.CreateInstance:无法从程序集中加载类型

来自分类Dev

无法加载类型'Microsoft.ApplicationInsights.Telemetry.Web.ApplicationInsightsModule'

来自分类Dev

Visual Studio无法从global.asax加载类型

来自分类Dev

无效的Resx文件。为什么无法加载类型错误?

来自分类Dev

启动ServiceStack时无法加载类型'ServiceStack.ServiceHost.IService'

来自分类Dev

无法加载类型'System.Web.Mvc.ViewPage'

Related 相关文章

  1. 1

    迁移应用程序时无法加载类型'Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions'

  2. 2

    CodeBehind 无法加载类型

  3. 3

    无法加载类型提交symfony 3

  4. 4

    无法加载类型“ WebApplication1.SiteMaster”

  5. 5

    Glide无法加载此类型的网址图片

  6. 6

    无法加载类型ASP.ViewSwitcher

  7. 7

    无法加载类型“ test.request”

  8. 8

    Symfony Crud Edict:无法加载类型“ datetime”

  9. 9

    CSS无法加载错误的MIME类型Django

  10. 10

    F#TypeProvider无法加载类型

  11. 11

    Symfony2无法加载类型EntityType

  12. 12

    无法使用Azure signalR加载类型MessagePack

  13. 13

    Glide无法加载此类型的网址图片

  14. 14

    无法加载类型“ WebApplication1.SiteMaster”

  15. 15

    无法加载类型“ Gregwar \ CaptchaBundle \ Type \ CaptchaType”

  16. 16

    IIS错误:无法加载类型“ IsapiModule”

  17. 17

    无法加载类型“Doctrine\DBAL\Types\TextType”

  18. 18

    Symfony 3-无法加载类型表单类型

  19. 19

    “无效的Resx文件,无法加载类型(类型)”不断返回

  20. 20

    无法从程序集“System.Drawing, Version=4.0.0.0”的加载类型“System.Drawing.Font”加载类型

  21. 21

    “无法加载类型<Namespace>。<Module>”是什么意思?

  22. 22

    无法加载类型'Common.Logging.Factory.AbstractCachingLoggerFactoryAdapter'

  23. 23

    无法加载类型'System.ComponentModel.DataAnnotations.Schema.IndexAttribute'

  24. 24

    Activator.CreateInstance:无法从程序集中加载类型

  25. 25

    无法加载类型'Microsoft.ApplicationInsights.Telemetry.Web.ApplicationInsightsModule'

  26. 26

    Visual Studio无法从global.asax加载类型

  27. 27

    无效的Resx文件。为什么无法加载类型错误?

  28. 28

    启动ServiceStack时无法加载类型'ServiceStack.ServiceHost.IService'

  29. 29

    无法加载类型'System.Web.Mvc.ViewPage'

热门标签

归档