PDJJ14 WIKI : System.InvalidOperationException 문제 해결

12. 현상

  • Entity Framework 를 이용하여 Table 에 데이터를 입력하려 할 때, 아래 그림과 같은 Exception 발생
    • Error Message
      • 고정 이름이 'System.Data.SqlClient'인 ADO.NET 공급자에 대해 응용 프로그램 구성 파일에 등록된 Entity Framework 공급자 형식 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer'을(를) 로드할 수 없습니다. 정규화된 어셈블리 이름이 사용되어 어셈블리를 실행 중인 응용 프로그램에서 사용할 수 있는지 확인하십시오. 자세한 내용은 http://go.microsoft.com/fwlink/?LinkId=260882 를 참조하십시오.
    • Stack Trace
      • 위치: System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName)
        위치: System.Data.Entity.Internal.AppConfig.<.ctor>b__2(ProviderElement e)
        위치: System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
        위치: System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
        위치: System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
        위치: System.Lazy`1.CreateValue()
        위치: System.Lazy`1.LazyInitValue()
        위치: System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.RegisterDbProviderServices()
        위치: System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetServiceFactory(Type type, String name)
        위치: System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
        위치: System.Data.Entity.Infrastructure.DependencyResolution.AppConfigDependencyResolver.GetService(Type type, Object key)
        위치: System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
        위치: System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
        위치: System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver`2.GetService(Type type, Object key)
        위치: System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver)
        위치: System.Data.Entity.DbContext.InitializeLazyInternalContext(IInternalConnection internalConnection, DbCompiledModel model)
        위치: FTS.Server.Database.FTSEntities..ctor() 파일 D:\Users\jjhan\Projects\FTS\FTS.Server\FTS.Server.Database\FtsDb.Context.cs:줄 19
        위치: FTS.Server.Database.DBManager.write(TB_FIS_Scheduler newItem) 파일 D:\Users\jjhan\Projects\FTS\FTS.Server\FTS.Server.Database\DBManager.cs:줄 166
        위치: FTS.Server.FIS.TaskManager.ExecuteTask(FTSTask _tTask) 파일 D:\Users\jjhan\Projects\FTS\FTS.Server\FTS.Server\FTS.Server.FIS\TaskManager.cs:줄 344
        위치: FTS.Server.FIS.TaskManager.ExecuteTaskThread(Object oTask) 파일 D:\Users\jjhan\Projects\FTS\FTS.Server\FTS.Server\FTS.Server.FIS\TaskManager.cs:줄 238
        위치: System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
        위치: System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
        위치: System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
        위치: System.Threading.ThreadPoolWorkQueue.Dispatch()

13. 문제 해결을 위한 시도

13.2. App.Config 에 FTSEntities 항목 추가

  • Entity Framework Class 를 추가한 프로젝트의 App.config 에 추가했으나 현상 동일
  • 최종적으로 Entity Framework Class 를 사용하는 프로젝트의 App.config 에 추가했으나 현상 동일

13.3. EF Class 가 포함되는 프로젝트를 참조하는 프로젝트의 Entity Framework 를 제거하고 다시 설치

  • 정상 동작!!!

13.4. 새로운 프로젝트에서 Entity Framework Class 생성 방법에 따라 결과 확인

13.4.1. FTS Log 프로젝트

  • Console 프로그램
  • 데이터베이스 프로젝트 참조
  • nuget 에서 EF 6.1.3 설치

13.4.2. ADO.Net 엔터티 데이터 모델 이용하여 생성

생성 항목생성 단계FTS Log 프로젝트를 이용한 Table Row 입출력 결과
ADO.Net 엔터티 데이터 모델
  1. 모델 컨텐츠: 데이터베이스의 EF Designer
  2. 데이터 연결
    1. 연결 속성
      1. 서버이름: ccm
      2. 인증: SQL Server 인증
      3. 사용자 이름: sa
      4. 비밀번호: engxxxxxxx
      5. 데이터베이스: DB_DTK
    2. 연결문자열 포함 여부: 아니오
    3. App.config 에 연결 설정 저장: 체크해제
  3. 사용할 EF 버전: 6.x
  4. 데이터베이스 개체: TB_FIS_Scheduler
    1. 체크항목
      1. 모델에 외래 키 열 포함
      2. 선택한 저장 프로시저 및 함수를 엔터티 모델로 가져오기
    2. 모델 네임스페이스
      1. DB_DTKModel

Exception 이 발생하지만 문제 현상과는 달랐음

 

 App.config 에 연결 설정 저장: 체크현상 동일
 App.config 에 기록되어 있는 <connectionString> 정보를 FTS Log 프로젝트의 App.config 에 추가정상 동작
EF 5.x DbContext 생성기할 필요 없었음 
EF 6.x DbContext 생성기  

Attachments: