1. ホーム
  2. c#

[解決済み】Entity Frameworkプロバイダタイプをロードできませんでしたか?

2022-03-24 20:12:14

質問

現在、私のマシンにインストールされているTeamCityでテストを実行しようとしています。

System.InvalidOperationException :

Entity Frameworkプロバイダタイプ ' 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 EF6にアップグレードするためにcodeplexで提案されたように、私のプロジェクトのいずれにおいても。

なぜこのような例外が発生するのか、よくわかりません。 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

解決方法は?

同じ問題ですが、私はNugetを通してEF 6をインストールしました。EntityFramework.SqlServerは、別の実行ファイルで欠落していました。私は単にそのプロジェクトにnugetパッケージを追加しました。