【发布时间】:2012-12-11 13:48:12
【问题描述】:
我正在尝试在我的机器上当前安装的 TeamCity 上运行测试。
System.InvalidOperationException:实体框架提供程序类型 '
System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer,Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'对于'System.Data.SqlClient' 无法加载 ADO.NET 提供程序。确保提供程序程序集 可用于正在运行的应用程序。请参阅http://go.microsoft.com/fwlink/?LinkId=260882 了解更多信息 信息..
我的任何项目中都没有提到 System.Data.Entity,正如 codeplex 上建议的升级到 EF6。
所以,我不确定为什么会出现此异常。 当我从 VS 运行测试时,我没有遇到任何此类异常。
我确实尝试将 CopyLocal 设置为 false,然后再次设置为 true.. 但这似乎也不起作用。
更新
我的 app.config 有以下内容。这会导致一些我不理解的行为吗?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
我在 teamcity 中得到以下堆栈跟踪。
[MSTest] IntegrationTests.CrudTest+QuestionTest.Create
[03:59:11][IntegrationTests.CrudTest+QuestionTest.Create] Initialization method IntegrationTests.CrudTest+QuestionTest.Initialize threw exception. System.InvalidOperationException: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' for the 'System.Data.SqlClient' ADO.NET provider could not be loaded. Make sure the provider assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information..
[03:59:11]
[IntegrationTests.CrudTest+QuestionTest.Create] at System.Data.Entity.Config.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName)
at System.Data.Entity.Config.ProviderServicesFactory.GetInstanceByConvention(String providerInvariantName)
at System.Data.Entity.Config.DefaultProviderServicesResolver.GetService(Type type, Object key)
at System.Data.Entity.Config.CachingDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple`2 k)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at System.Data.Entity.Config.CachingDependencyResolver.GetService(Type type, Object key)
at System.Data.Entity.Config.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at System.Data.Entity.Config.ResolverChain.GetService(Type type, Object key)
at System.Data.Entity.Config.RootDependencyResolver.GetService(Type type, Object key)
at System.Data.Entity.Config.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at System.Data.Entity.Config.ResolverChain.GetService(Type type, Object key)
at System.Data.Entity.Config.CompositeResolver`2.GetService(Type type, Object key)
at System.Data.Entity.Config.IDbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver, Object key)
at System.Data.Entity.Config.InternalConfiguration.GetService[TService](Object key)
at System.Data.Entity.Config.DbConfiguration.GetService[TService](Object key)
at System.Data.Entity.Utilities.DbProviderFactoryExtensions.GetProviderServices(DbProviderFactory factory)
at System.Data.Entity.Infrastructure.DefaultManifestTokenService.GetProviderManifestToken(DbConnection connection)
at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
at System.Data.Entity.DbSet`1.Add(TEntity entity)
at EFRepository.Infrastructure.EFRepository`1.Add(T item) in c:\TeamCity\buildAgent\work\da2ea4e72c0e77f0\Repository\Infrastructure\EFRepository.cs:line 22
at IntegrationTests.CrudTest.Initialize() in c:\TeamCity\buildAgent\work\da2ea4e72c0e77f0\IntegrationTests\CrudTest.cs:line 34
【问题讨论】:
-
EntityFramework.SqlServer.dll 是否与 EntityFramework.dll 一起部署?在 EF6 中,SqlServer 和 SqlServerCE 提供程序与之前版本的 EF 引擎不在同一个程序集中。您不应添加对 System.Data.Entity.dll 的引用。与 EF5 相比,EF6 中的提供程序模型发生了变化,而 EF5 提供程序将无法正常工作。此外,您可能会遇到一些棘手的问题(例如 EF5 地理空间类型在 EF6 中被视为实体类型)
-
是的,我仔细检查了没有对 System.Data.Entity 的引用,并且对 EntityFramework.dll 和 EntityFramework.SqlServer.dll 的引用都存在。 projetc 再次编译并在 VS 中运行测试。只有当我在 TeamCity 上运行测试时才会出现错误。
-
这是一个正确的设置。我没有使用 TeamCity,但在我看来,当您的应用程序被部署以使用 TeamCity 运行测试时,EntityFramework.SqlServer.dll 丢失,因此出现异常。
-
查看这篇文章的答案:stackoverflow.com/questions/21175713/… 我添加了
private volatile Type _dependency...答案,它成功了!只是为了让 EF 在 TeamCity 中工作,我必须添加一个像这样的单独类。 -
我从 nuget 包中卸载了 EntityFramework 并再次安装,它得到了修复
标签: c# entity-framework mstest teamcity-7.1 entity-framework-6