无法加载类型'Microsoft.Framework.Configuration.Helper.ConfigurationHelper'

时间:2015-11-10 18:08:33

标签: entity-framework asp.net-core dnx dnvm

我的models文件夹中有两个简单的poco类我想使用实体框架来创建一个迁移。我还有一个dbcontext类,它是我想用作迁移的实例。

当我尝试运行时:dnx ef migrations添加IntialCommit

我收到以下错误无法从程序集'Microsoft.Framework.Configuration,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'加载类型'Microsoft.Framework.Configuration.Helper.ConfigurationHelper'。

即使我有正确的包,(Microsoft.Framework.Configuration)

任何想法我为什么会收到此错误?

AnimalsContext.cs

public class Animalscontext :DbContext
{
    public DbSet<Animalscontext> animals  { get; set; }
    public DbSet<Dog> dog { get; set; }

}

Animals.cs

     public class Animals
        {

            public int ID { get; set; }
            public string Name { get; set; }

            public List<Dog> dogs { get; set; }
}

Dog.cs

 public class Dog
{

    public int ID { get; set; }

    public string breed { get; set; }
}

project.json

  "dependencies": {
    "EntityFramework.Commands": "7.0.0-*",
    "EntityFramework.SqlServer": "7.0.0-*",
    "Microsoft.AspNet.Diagnostics": "1.0.0-*",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*",
    "Microsoft.AspNet.Mvc": "6.0.0-*",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-*",
    "Microsoft.AspNet.Server.IIS": "1.0.0-*",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-*",
    "Microsoft.AspNet.StaticFiles": "1.0.0-*",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-*",
    "Microsoft.Framework.Configuration": "1.0.0-*",
    "Microsoft.Framework.Configuration.CommandLine": "1.0.0-*",
    "Microsoft.Framework.Configuration.Json": "1.0.0-*",
    "Microsoft.Framework.Logging": "1.0.0-*",
    "Microsoft.Framework.Logging.Console": "1.0.0-*",
    "Microsoft.Framework.Logging.Debug": "1.0.0-*",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-*"
  },

  "commands": {
    "web": "Microsoft.AspNet.Hosting --config hosting.ini",
    "ef": "EntityFramework.Commands"
  }

Startup.cs

services.AddEntityFramework()
                .AddSqlServer()
                .AddDbContext<Animalscontext>(DbContextOptionsBuilder => DbContextOptionsBuilder.UseSqlServer(connectionString));

输出

Using context 'Animalscontext'.
System.TypeLoadException: Could not load type 'Microsoft.Framework.Configuration.Helper.ConfigurationHelper' from assembly 'Microsoft.Framework.Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at Microsoft.Framework.Configuration.JsonConfigurationExtensions.AddJsonFile(IConfigurationBuilder configuration, String path, Boolean optional)
   at WebApplication2.Startup..ctor(IHostingEnvironment env, IApplicationEnvironment appEnv) in C:\Users\JConterio\Documents\Visual Studio 2015\Projects\WebApplication2\src\WebApplication2\Startup.cs:line 21
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Framework.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
   at Microsoft.Framework.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type)
   at Microsoft.AspNet.Hosting.Startup.StartupLoader.LoadMethods(Type startupType, IList`1 diagnosticMessages)
   at Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureStartup()
   at Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureApplicationServices()
   at Microsoft.AspNet.Hosting.Internal.HostingEngine.get_ApplicationServices()
   at Microsoft.Data.Entity.Design.DbContextOperations.TryCreateContextFromStartup(Type type)
   at Microsoft.Data.Entity.Design.DbContextOperations.CreateContext(String contextType)
   at Microsoft.Data.Entity.Design.MigrationsOperations.AddMigration(String name, String contextType)
   at Microsoft.Data.Entity.Commands.Program.AddMigration(String name, String context)
   at Microsoft.Data.Entity.Commands.Program.<>c__DisplayClass7_6.<Main>b__15()
   at Microsoft.Dnx.Runtime.Common.CommandLine.CommandLineApplication.Execute(String[] args)
   at Microsoft.Data.Entity.Commands.Program.Main(String[] args)
Could not load type 'Microsoft.Framework.Configuration.Helper.ConfigurationHelper' from assembly 'Microsoft.Framework.Configuration, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.

1 个答案:

答案 0 :(得分:1)

尽量避免使用1.0.0-*,除非您的目的是测试夜间构建。

尝试使用已发布和测试过的1.0.0-beta8等特定包。要确保您使用的是最新的软件包,请更改您的参考资料,然后重试。如果你有VS2015,请确保将工具更新到Beta8。

这可以解决你的大部分问题。否则,请尝试使用最新测试版的“文件&gt;新项目”并比较您的project.json文件。