测试proejct测试将不会执行:无法识别的配置部分entityFramework

当我尝试运行测试时,我的app.config中的测试项目出现以下错误:

Result Message: Test method MYTESTPROJ.Repositories.MYREPO.MY_TEST threw exception: System.TypeInitializationException: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section entityFramework. (C:\Dev\trunk\MYTESTPROJ\bin\Debug\MYTESTPROJ.dll.config line 20) Result StackTrace: at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal) at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors) at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors() at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey) --- End of inner exception stack trace --- at System.Configuration.ConfigurationManager.PrepareConfigSystem() at System.Configuration.ConfigurationManager.GetSection(String sectionName) at System.Configuration.ConfigurationManager.get_ConnectionStrings() at System.Data.Entity.Internal.AppConfig..ctor() at System.Data.Entity.Internal.AppConfig..cctor() --- End of inner exception stack trace --- at System.Data.Entity.Internal.AppConfig.get_DefaultInstance() at System.Data.Entity.Internal.LazyInternalConnection..ctor(DbContext context, String nameOrConnectionString) at System.Data.Entity.DbContext..ctor(String nameOrConnectionString) 

这是我的app.config:

                           

您只需在顶部添加configSections区域即可注册该部分(您可能需要更改EF版本)。

    

有同样的错误,但我认为我有configSections声明…我错误地将它放在sectionGroup而不是configSection中。

错误:

    
...

正确:

    

我在更新.net framework 4.5.2之后遇到了这个问题。 似乎更新的.net框架也将EntityFramework版本从5.xx更新到6.1.2。

但是在web.config中它仍然没有改变。 它是5.0.0.0,如果我将此值更改为6.1.2以匹配NuGet包管理器中显示的EF版本。 这没有任何好处。 然后我扩展了我的项目References节点,右键单击EntityFramework,显示的版本为6.0.0.0。 使用此值而不是6.1.2,一切都开始工作。