You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Entity Framework Core添加迁移时遇System.AccessViolationException错误

Entity Framework Core创建迁移时触发System.AccessViolationException错误

我在用Entity Framework Core创建迁移时遇到了System.AccessViolationException错误,无论是在Visual Studio包管理器控制台还是PowerShell中使用CLI执行,都会出现相同的错误。

CLI执行示例及输出如下:

PS dotnet ef migrations add [migration-name] --project [project-name] --startup-project [project-name]
Build started...
Build succeeded.

随后抛出的致命错误信息:

Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

at System.Diagnostics.StackTrace.GetStackFramesInternal(System.Diagnostics.StackFrameHelper, Int32, Boolean, System.Exception)
at System.Diagnostics.StackFrameHelper.InitializeSourceInfo(Int32, Boolean, System.Exception)
at System.Diagnostics.StackTrace.CaptureStackTrace(Int32, Boolean, System.Exception)
at System.Diagnostics.StackTrace..ctor(System.Exception, Boolean)
at System.Exception.get_StackTrace()
at System.Exception.ToString()
at System.Exception.ToString()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor+OperationBase.Execute(System.Action)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor+OperationBase.Execute[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]
at Microsoft.EntityFrameworkCore.Design.OperationExecutor+AddMigration..ctor(Microsoft.EntityFrameworkCore.Design.OperationExecutor, Microsoft.EntityFrameworkCore.Design.IOperationResultHandler, System.Collections.IDictionary)
at System.RuntimeMethodHandle.InvokeMethod(System.Object, System.Object[], System.Signature, Boolean, Boolean)
at System.Reflection.RuntimeConstructorInfo.Invoke(System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
at System.RuntimeType.CreateInstanceImpl(System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo)
at System.Activator.CreateInstance(System.Type, System.Reflection.BindingFlags, System.Reflection.Binder, System.Object[], System.Globalization.CultureInfo, System.Object[])
at System.Activator.CreateInstance(System.Type, System.Object[])
at Microsoft.EntityFrameworkCore.Tools.ReflectionOperationExecutor.Execute(System.String, System.Object, System.Collections.IDictionary)
at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Runtime.CompilerServices.CallSite, System.__Canon, System.__Canon, System.__Canon, System.__Canon)
at Microsoft.EntityFrameworkCore.Tools.OperationExecutorBase.InvokeOperationImpl(System.String, System.Collections.IDictionary)
at Microsoft.EntityFrameworkCore.Tools.OperationExecutorBase.InvokeOperation[[System.__Canon, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.String, System.Collections.IDictionary)
at Microsoft.EntityFrameworkCore.Tools.OperationExecutorBase.AddMigration(System.String, System.String, System.String)
at Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsAddCommand.Execute()
at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase+<>c__DisplayClass0_0.b__0()
at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(System.String[])
at Microsoft.EntityFrameworkCore.Tools.Program.Main(System.String[])

我已经尝试过重启电脑、运行Windows内存诊断测试,但都未能解决问题。之前我可以正常创建迁移,本次仅为实体类新增了一个属性(对应数据库表新增一列),就出现了这个错误,请问有人知道原因吗?

内容的提问来源于stack exchange,提问作者Iúri dos Anjos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 14:36:25