0

我有一个由 Visual Studio 为我生成的数据库优先实体框架模型和上下文,当直接从测试项目中引用时它们很好。

但是,现在我试图通过 MEF 导出上下文和存储库并导入我的模块之一。但是,当我运行该应用程序时,出现以下错误

The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.

1) The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

Resulting in: An exception occurred while trying to create an instance of type 'InsuranceManager.Data.Context.InsuranceDataContext'.

Resulting in: Cannot activate part 'InsuranceManager.Data.Context.InsuranceDataContext'.
Element: InsuranceManager.Data.Context.InsuranceDataContext -->  InsuranceManager.Data.Context.InsuranceDataContext -->  AssemblyCatalog (Assembly="InsuranceManager.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

Resulting in: Cannot get export 'InsuranceManager.Data.Context.InsuranceDataContext (ContractName="InsuranceManager.Data.Context.InsuranceDataContext")' from part 'InsuranceManager.Data.Context.InsuranceDataContext'.
Element: InsuranceManager.Data.Context.InsuranceDataContext (ContractName="InsuranceManager.Data.Context.InsuranceDataContext") -->  InsuranceManager.Data.Context.InsuranceDataContext -->  AssemblyCatalog (Assembly="InsuranceManager.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

Resulting in: Cannot set import 'InsuranceManager.Data.Repository.InsuranceRepository..ctor (Parameter="context", ContractName="InsuranceManager.Data.Context.InsuranceDataContext")' on part 'InsuranceManager.Data.Repository.InsuranceRepository'.
Element: InsuranceManager.Data.Repository.InsuranceRepository..ctor (Parameter="context", ContractName="InsuranceManager.Data.Context.InsuranceDataContext") -->  InsuranceManager.Data.Repository.InsuranceRepository -->  AssemblyCatalog (Assembly="InsuranceManager.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

Resulting in: Cannot get export 'InsuranceManager.Data.Repository.InsuranceRepository (ContractName="InsuranceManager.Data.Interface.IDataRepository")' from part 'InsuranceManager.Data.Repository.InsuranceRepository'.
Element: InsuranceManager.Data.Repository.InsuranceRepository (ContractName="InsuranceManager.Data.Interface.IDataRepository") -->  InsuranceManager.Data.Repository.InsuranceRepository -->  AssemblyCatalog (Assembly="InsuranceManager.Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

Resulting in: Cannot set import 'InsuranceManager.GUI.MaintenanceModule.ViewModel.GeoRegionMaintenanceViewModel..ctor (Parameter="repository", ContractName="InsuranceManager.Data.Interface.IDataRepository")' on part 'InsuranceManager.GUI.MaintenanceModule.ViewModel.GeoRegionMaintenanceViewModel'.
Element: InsuranceManager.GUI.MaintenanceModule.ViewModel.GeoRegionMaintenanceViewModel..ctor (Parameter="repository", ContractName="InsuranceManager.Data.Interface.IDataRepository") -->  InsuranceManager.GUI.MaintenanceModule.ViewModel.GeoRegionMaintenanceViewModel -->  AssemblyCatalog (Assembly="InsuranceManager.GUI.MaintenanceModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

Resulting in: Cannot get export 'InsuranceManager.GUI.MaintenanceModule.ViewModel.GeoRegionMaintenanceViewModel (ContractName="InsuranceManager.GUI.MaintenanceModule.ViewModel.GeoRegionMaintenanceViewModel")' from part 'InsuranceManager.GUI.MaintenanceModule.ViewModel.GeoRegionMaintenanceViewModel'.
Element: InsuranceManager.GUI.MaintenanceModule.ViewModel.GeoRegionMaintenanceViewModel (ContractName="InsuranceManager.GUI.MaintenanceModule.ViewModel.GeoRegionMaintenanceViewModel") -->  InsuranceManager.GUI.MaintenanceModule.ViewModel.GeoRegionMaintenanceViewModel -->  AssemblyCatalog (Assembly="InsuranceManager.GUI.MaintenanceModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

Resulting in: Cannot set import 'InsuranceManager.GUI.MaintenanceModule.View.GeoRegionMaintenanceView.ViewModel (ContractName="InsuranceManager.GUI.MaintenanceModule.ViewModel.GeoRegionMaintenanceViewModel")' on part 'InsuranceManager.GUI.MaintenanceModule.View.GeoRegionMaintenanceView'.
Element: InsuranceManager.GUI.MaintenanceModule.View.GeoRegionMaintenanceView.ViewModel (ContractName="InsuranceManager.GUI.MaintenanceModule.ViewModel.GeoRegionMaintenanceViewModel") -->  InsuranceManager.GUI.MaintenanceModule.View.GeoRegionMaintenanceView -->  AssemblyCatalog (Assembly="InsuranceManager.GUI.MaintenanceModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

Resulting in: Cannot get export 'InsuranceManager.GUI.MaintenanceModule.View.GeoRegionMaintenanceView (ContractName="System.Object")' from part 'InsuranceManager.GUI.MaintenanceModule.View.GeoRegionMaintenanceView'.
Element: InsuranceManager.GUI.MaintenanceModule.View.GeoRegionMaintenanceView (ContractName="System.Object") -->  InsuranceManager.GUI.MaintenanceModule.View.GeoRegionMaintenanceView -->  AssemblyCatalog (Assembly="InsuranceManager.GUI.MaintenanceModule, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null")

谁能帮助我了解这可能意味着什么以及从哪里开始寻找?

4

1 回答 1

1

确保 EntityFramework.SqlServer.dll 和 EntityFramework.SqlServer.xml 文件与正在运行的应用程序位于同一目录中。在过去,这不是问题,但对于 EF 6.0,您必须做出安排以确保在运行时找到 SQL Server 提供程序 (EntityFramework.SqlServer.dll)。我发现的最简单的方法是使用 EF 6.0 为项目进行 nuget-it。我建议熟悉http://msdn.microsoft.com/en-us/data/jj730568#noProvider中记录的其他一些注意事项。高温高压

解决它的另一种方法(我刚刚做过)是使用 EF 将以下代码行添加到类的 ctor 中:

var typeOfSqlProviderServices = typeof(System.Data.Entity.SqlServer.SqlProviderServices);

它对我有用。

于 2013-12-04T16:59:13.180 回答