无法加载实体框架提供程序类型? [英] Entity Framework Provider type could not be loaded?

查看:22
本文介绍了无法加载实体框架提供程序类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在当前安装在我机器上的 TeamCity 上运行我的测试.

I am trying to run my tests on TeamCity which is currently installed on my machine.

System.InvalidOperationException:

实体框架提供程序类型'<代码>System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral,'System.Data.SqlClient' 的 PublicKeyToken=b77a5c561934e089'无法加载 ADO.NET 提供程序.确保提供程序程序集可用于正在运行的应用程序.

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.

请参阅 http://go.microsoft.com/fwlink/?LinkId=260882 了解更多信息信息..

See http://go.microsoft.com/fwlink/?LinkId=260882 for more information..

我在我的任何项目中都没有提到 System.Data.Entity,正如 codeplex 上建议的那样,以升级到 EF6.

I have no reference to System.Data.Entity in any of my projects as was suggested on codeplex for upgrading to EF6.

所以,我不确定为什么我会收到此异常.当我从 VS 运行测试时,我没有遇到任何此类异常.

So, I am not sure why am I getting this exception. I do not get any such exception when I run the tests from VS.

我确实尝试将 CopyLocal 设置为 false 然后再次设置为 true.. 但这似乎也不起作用.

I did try to set CopyLocal to false then again to true.. but that does not seem to work either.

更新

我的 app.config 有以下内容.这是否会导致一些我不理解的行为?

My app.config has the following . Does this cause some behavior that I don't understand ?

<?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 中得到以下堆栈跟踪.

I get the following stacktrace in 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:TeamCityuildAgentworkda2ea4e72c0e77f0RepositoryInfrastructureEFRepository.cs:line 22
   at IntegrationTests.CrudTest.Initialize() in c:TeamCityuildAgentworkda2ea4e72c0e77f0IntegrationTestsCrudTest.cs:line 34

推荐答案

我在我的测试项目中遇到了同样的问题 - 我通过 NuGet 安装了最新的 EF6 位,并且每次我调用与 EF 相关的东西时:

I had the same problem in my Test projects - I installed the latest EF6 bits via NuGet and everytime I invoke something EF-related I got:

实体框架提供程序类型'System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer' 用于'System.Data.SqlClient' ADO.NET无法加载提供程序.确保提供程序程序集是可用于正在运行的应用程序.看http://go.microsoft.com/fwlink/?LinkId=260882 了解更多信息.

The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' 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.

我的解决方法:我将此方法放在我的测试项目中:

My workaround: I placed this method inside my test project:

public void FixEfProviderServicesProblem()
{
//The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer'
//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.

var instance = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
}

从未调用过此方法,但我认为编译器将删除所有不必要的"程序集,并且在不使用 EntityFramework.SqlServer 内容的情况下测试失败.

This method is never been called, but I think the compiler will remove all "unnecessary" assemblies and without using the EntityFramework.SqlServer stuff the test fails.

无论如何:在我的机器上工作;)

Anyways: Works on my machine ;)

注意:您可以确保模型/实体项目中对 SqlProviderServices 的静态引用,而不是将方法添加到测试项目中.

这篇关于无法加载实体框架提供程序类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆