ash*_*ina 406 c# mstest entity-framework teamcity-7.1 entity-framework-6
我正在尝试在我的机器上安装的TeamCity上运行我的测试.
System.InvalidOperationException:实体框架提供程序类型" 为" 'ADO.NET提供程序无法加载.确保提供程序程序集可用于正在运行的应用程序.
System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServerVersion=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'System.Data.SqlClient
我没有参考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>
Run Code Online (Sandbox Code Playgroud)
我在teamcity中得到以下stacktrace.
[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
Run Code Online (Sandbox Code Playgroud)
Zap*_*ila 415
同样的问题,但我通过Nuget安装了EF 6.另一个可执行文件缺少EntityFramework.SqlServer.我只是将nuget包添加到该项目中.
Rob*_*sig 270
我在我的测试项目中遇到了同样的问题 - 我通过NuGet安装了最新的EF6位,每次我调用与EF相关的东西:
无法加载"System.Data.SqlClient"ADO.NET提供程序的Entity Framework提供程序类型"System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer".确保提供程序程序集可用于正在运行的应用程序.有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkId=260882.
我的解决方法:我将此方法放在我的测试项目中:
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;
}
Run Code Online (Sandbox Code Playgroud)
从未调用此方法,但我认为编译器将删除所有"不必要的"程序集,而不使用EntityFramework.SqlServer,测试失败.
无论如何:在我的机器上工作;)
注意:您可以确保从模型/实体项目中对SqlProviderServices进行静态引用,而不是将该方法添加到测试项目中.
Tim*_*ver 105
Nuget将配置您的EF6项目以引用EntityFramework.SqlServer.dll.这将在构建期间部署到EF6项目的输出文件夹,但不会部署到引用EF6项目的项目的输出文件夹.我相信这是因为Visual Studio足够"智能",可以检测到程序集中没有任何内容实际上直接使用dll,因此不包含它.您可以通过向使用EntityFramework.SqlServer.dll的EF6项目添加代码,强制EntityFramework.SqlServer.dll部署到引用您的EF6项目的项目的输出文件夹(单元测试,UI等).注意不要将代码放在生成的类中,因为在下次重新生成时可能会丢失它.我选择将以下类添加到程序集中,从而解决了问题.
using System.Data.Entity.SqlServer;
internal static class MissingDllHack
{
// Must reference a type in EntityFramework.SqlServer.dll so that this dll will be
// included in the output folder of referencing projects without requiring a direct
// dependency on Entity Framework. See http://stackoverflow.com/a/22315164/1141360.
private static SqlProviderServices instance = SqlProviderServices.Instance;
}
Run Code Online (Sandbox Code Playgroud)
Kev*_*vbo 42
我的解决方案是通过nuget管理器从项目中删除实体框架并将其重新添加.
小智 29
我通过在DBContext类的顶部添加一个using stament来解决这个问题,如下所示:
using SqlProviderServices= System.Data.Entity.SqlServer.SqlProviderServices;
Run Code Online (Sandbox Code Playgroud)
小智 20
我已经为提供商使用了基于代码的注册. link1 link2
刚刚创建了配置类
class DbContextConfiguration : DbConfiguration
{
public DbContextConfiguration()
{
this.SetDatabaseInitializer(new DropCreateDatabaseAlways<MyDbContext>());
this.SetProviderServices(SqlProviderServices.ProviderInvariantName, SqlProviderServices.Instance);
}
}
Run Code Online (Sandbox Code Playgroud)
关键点是this.SetProviderServices(SqlProviderServices.ProviderInvariantName,SqlProviderServices.Instance);
并以这种方式使用它
[DbConfigurationType(typeof(DbContextConfiguration))]
public class MyDbContext : DbContext
{
public MyDbContext()
{
...
}
public DbSet<...> ...{ get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
Ran*_*dom 14
我在程序集初始化类中用[DeploymentItem]对它进行了整理
namespace MyTests
{
/// <summary>
/// Summary description for AssemblyTestInit
/// </summary>
[TestClass]
[DeploymentItem("EntityFramework.SqlServer.dll")]
public class AssemblyTestInit
{
public AssemblyTestInit()
{
}
private TestContext testContextInstance;
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
[AssemblyInitialize()]
public static void DbContextInitialize(TestContext testContext)
{
Database.SetInitializer<TestContext>(new TestContextInitializer());
}
}
}
Run Code Online (Sandbox Code Playgroud)
迟到了,但最高投票的答案对我来说都像是黑客.
我所做的就是从测试项目中的app.config中删除以下内容.工作.
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
Run Code Online (Sandbox Code Playgroud)
小智 8
我有问题,因为我没有添加对EntityFramework.sqlServer.dll的引用.当我开发程序时,它可以工作.但是当我发布应用程序并安装它时,它会抛出错误.
我只是再次添加引用和Build and Publish.

小智 5
我遇到了同样的问题,我尝试了很多次,但没有解决,但是当我安装 EntityFramework.SqlServerCompact 包时,它解决了从 Nuget 包管理器安装此包的问题。
Install-Package EntityFramework.SqlServerCompact
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
258314 次 |
| 最近记录: |