EF核心迁移失败:System.Runtime.Remoting.RemotingException:无法加载类型' Microsoft.EntityFrameworkCore.Design.IOperationResultHandler

时间:2017-04-04 07:51:51

标签: c# entity-framework-core ef-migrations

我第一次将Entity Framework核心迁移到我的平均大小项目(大约100个表),现在我正在尝试使用' Update-Database'对azure sql db进行更改。在包管理器控制台中调用。

我总会得到这个错误: 异常消息: 堆栈跟踪:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.Remoting.RemotingException: Cannot load type 'Microsoft.EntityFrameworkCore.Design.IOperationResultHandler, Microsoft.EntityFrameworkCore.Design, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

Server stack trace:
at System.Runtime.Remoting.Messaging.MethodCall.ResolveMethod(Boolean bThrowIfNotResolved)
at System.Runtime.Remoting.Messaging.MethodCall..ctor(SmuggledMethodCallMessage smuggledMsg, ArrayList deserializedArgs)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoDispatch(Byte[] reqStmBuff, SmuggledMethodCallMessage smuggledMcm, SmuggledMethodReturnMessage& smuggledMrm)
at System.Runtime.Remoting.Channels.CrossAppDomainSink.DoTransitionDispatchCallback(Object[] args)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.EntityFrameworkCore.Design.IOperationResultHandler.OnError(String type, String message, String stackTrace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.AppDomain.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.AppDomain.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at Microsoft.EntityFrameworkCore.Tools.AppDomainOperationExecutor.Execute(String operationName, Object resultHandler, IDictionary arguments)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[T0,T1,T2,T3](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
at Microsoft.EntityFrameworkCore.Tools.OperationExecutorBase.InvokeOperationImpl(String operationName, IDictionary arguments)
at Microsoft.EntityFrameworkCore.Tools.OperationExecutorBase.UpdateDatabase(String migration, String contextType)
at Microsoft.EntityFrameworkCore.Tools.Commands.DatabaseUpdateCommand.Execute()
at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Exception has been thrown by the target of an invocation.

我知道它尝试删除此表主键 - 之前有多个类似的调用:

migrationBuilder.DropPrimaryKey(name: "pk_usr", table: "usr");

我的理由可能是什么原因 - 谢谢你的帮助!

引用我所拥有的内容(均为1.1.1.0):

Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.Relational
Microsoft.EntityFrameworkCore.Relational.Design
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.SqlServer.Design

2 个答案:

答案 0 :(得分:0)

检查this是否可以解决您的问题,如果没有,请继续执行以下选项 EF Tools 1.1.0-preview4 Unrecognized option '--config' #7071

  1. 您是否正在尝试更新已创建的数据库?如果是这样, 您的迁移可能与迁移数据库不同步 快照。你以前没有用它创建数据库表 迁移和/或添加或删除列或表而不使用 迁移,忘记使用当前的迁移并创建一个新的 数据库。
    1. 其他一些原因可能是您正在使用实体框架 class librarythis doesn't currently work;
    2. 另一个原因可能是使用某些软件包的.Net Core运行时 由于可能的更新,目前尚未引用,因此请确保 您正在使用引用的软件包
    3. 或可能是you updated your solution, or your solution used updated nuget packages that are not supported by the installed .NET Core Runtime. Ckeck that or the Vice versa

答案 1 :(得分:0)

您似乎正在使用Microsoft.EntityFrameworkCore.Tools的不兼容版本。确保已安装1.1.0版。