我有一个数据库优先的实体框架模型和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")
任何人都可以帮助我了解这可能意味着什么以及从哪里开始寻找?
答案 0 :(得分: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中记录的其他一些注意事项。 HTH
解决它的另一种方法(我刚才这样做)是使用EF将以下代码行添加到类的ctor中:
var typeOfSqlProviderServices = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
它对我有用。