EF System.MissingMethodException

4
我在一个C#项目中从SqlCe数据库生成EF模型时遇到了问题。这是一个新错误,因为我多年来进行了多次更新。我尝试了许多方法来解决它,也在网上进行了研究,但没有任何帮助我解决。我还将.NET Framework更改为4.6.2。
该C#项目使用的是NETFramework 4.5和EF 6.2,EF.SqlCe 6.2。
以下是错误消息:
Generating the model took 00:00:30.5059377.
Unable to generate the model because of the following exception: 'System.MissingMethodException: Method not found: 'Boolean System.Data.Entity.Core.Common.DbProviderManifest.SupportsParameterOptimizationInSchemaQueries()'.
   at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.EntityStoreSchemaGeneratorDatabaseSchemaLoader.CreateFilteredCommand(String sql, String orderByClause, EntityStoreSchemaFilterObjectTypes queryTypes, List`1 filters, String[] filterAliases)
   at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.EntityStoreSchemaGeneratorDatabaseSchemaLoader.LoadDataTable[T](String sql, Func`2 orderByFunc, DataTable table, EntityStoreSchemaFilterObjectTypes queryTypes, IEnumerable`1 filters, String[] filterAliases)
   at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.EntityStoreSchemaGeneratorDatabaseSchemaLoader.LoadTableDetails(IEnumerable`1 filters)
   at Microsoft.Data.Entity.Design.VersioningFacade.ReverseEngineerDb.SchemaDiscovery.EntityStoreSchemaGeneratorDatabaseSchemaLoader.LoadStoreSchemaDetails(IList`1 filters)
   at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.GetStoreSchemaDetails(StoreSchemaConnectionFactory connectionFactory)
   at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.CreateStoreModel()
   at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelGenerator.GenerateModel(List`1 errors)
   at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModels(String storeModelNamespace, ModelBuilderSettings settings, List`1 errors)
   at Microsoft.Data.Entity.Design.VisualStudio.ModelWizard.Engine.ModelBuilderEngine.GenerateModel(ModelBuilderSettings settings, IVsUtils vsUtils, ModelBuilderEngineHostContext hostContext)'.
Loading metadata from the database took 00:00:01.5131055.
Generating the model took 00:00:04.8109160.

有什么想法吗?

非常感谢你。


1
这已经被多人报告了。直接原因似乎是加载了错误版本的“EntityFramework.dll”,但间接原因,即为什么会加载错误版本,可能因个人而异。您能检查一下加载了哪个版本的EF吗? - user743382
4个回答

6

我曾以管理员身份运行此命令,成功解决了问题:

gacutil /u EntityFramework

需要重新启动Visual Studio,因为旧版程序集可能已安装到全局程序集缓存(GAC)中。

这对我在VS 2019中很有帮助。谢谢! - Kevin M. Lapio

1

我曾在使用VS 2017时遇到过这个问题。以下是我采取的步骤来解决这个问题:

  1. 进入"C:\Windows\Microsoft.NET\assembly\GAC_MSIL\EntityFramework"文件夹位置
  2. 从上述文件夹中剪切"EntityFramework.dll"并将其保留在其他地方
  3. 进入EF项目并更新模型,无需任何错误

希望这可以帮到你。谢谢。


我认为它已经起作用了,需要重新启动VS。(我更新了Entity Framework nuget,不知道是否会影响成功) - forX

0
在我的情况下,我有两个包引用了同一个dll的不同版本。例如,针对mysql和sqlite的EntityFramework包引用了不同版本的EntityFramework核心库。
从这样的角度来看,显而易见的解决方法是:
  • 删除其中一个冲突的包;或者
  • 确保您选择的两个包的版本引用了相同或兼容的冲突dll的版本。Nuget包管理器在这方面非常有用。
请记住,偶尔需要重新启动IDE才能捕获任何更改。

0

我重新安装了VS 2017,现在可以工作了!!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接