2017-11-16 26 views
9

Tôi đang làm việc với SQLite. Tôi có thể sử dụng Entity Framework 6.1.3 trong ứng dụng WPF của tôi không có vấn đề, nhưng khi tôi cập nhật nó để 6.2.0 Tôi nhận được lỗi sau:Cập nhật lên EF 6.2.0 từ EF 6.1.3 nguyên nhân không thể truy cập lỗi đối tượng được xử lý

Test method DataAccessLayerTests.GenericDataRepositoryTests.CRUD_On_Pipe threw exception: 
System.ObjectDisposedException: Cannot access a disposed object. 
Object name: 'SQLiteConnection'. 
    at System.Data.SQLite.SQLiteConnection.CheckDisposed() 
    at System.Data.SQLite.SQLiteConnection.get_State() 
    at System.Data.Entity.Internal.RepositoryBase.CreateConnection() 
    at System.Data.Entity.Migrations.History.HistoryRepository.QueryExists(String contextKey) 
    at System.Data.Entity.Migrations.History.HistoryRepository.Exists(String contextKey) 
    at System.Data.Entity.Migrations.History.HistoryRepository.GetPendingMigrations(IEnumerable`1 localMigrations) 
    at System.Data.Entity.Migrations.DbMigrator.GetPendingMigrations() 
    at Core.DatabaseContext.CreateAndSeedIfNotExists`1.InitializeDatabase(T context) in C:\Users\roadrunner\propulsimcs\Propulsim\Core\DatabaseContext.cs:line 40 
    at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf`1.<CreateInitializationAction>b__e() 
    at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) 
    at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() 
    at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) 
    at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) 
    at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) 
    at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() 
    at System.Data.Entity.Internal.InternalContext.Initialize() 
    at System.Data.Entity.Database.Initialize(Boolean force) 
    at Core.DatabaseContext..ctor() in C:\Users\roadrunner\propulsimcs\Propulsim\Core\DatabaseContext.cs:line 114 
    at DataAccessLayer.GenericDataRepository`1.GetAll(Expression`1[] navigationProperties) in C:\Users\roadrunner\propulsimcs\Propulsim\DataAccessLayer\GenericDataRepository.cs:line 16 
    at DataAccessLayerTests.GenericDataRepositoryTests.CRUD_On_Pipe() in C:\Users\roadrunner\propulsimcs\Propulsim\DataAccessLayerTests\GenericDataRepositoryTests.cs:line 34 




Debug Trace: 
Native library pre-loader is trying to load native SQLite library "C:\Users\roadrunner\propulsimcs\Propulsim\DataAccessLayerTests\bin\Debug\x86\SQLite.Interop.dll"... 

Bất kỳ ý tưởng?

+0

Vui lòng hiển thị cho chúng tôi mã nguồn cho 'CRUD_On_Pipe' và' GetAll'. – mjwills

+0

@mjwills Có Tôi đã cập nhật cả dự án ứng dụng và thử nghiệm. – ferit

+0

@mjwills Cập nhật câu hỏi với các mã nguồn đó. – ferit

Trả lời

5

Vấn đề là do sự thay đổi trong RepositoryBase lớp và không chính xác (IMO) thực hiện IDbConnection.State sở hữu bởi SQLiteConnection lớp (ném ObjectDisposedException thay vì trả lại ConnectionState.Closed khi kêu gọi các đối tượng xử lý).

Điều này giống như được báo cáo trong #398: NullReferenceException on Code First Migrations when Glimpse is installed. Theo tình trạng, nó đã được cố định trong kho lưu trữ EF6, nhưng tiếc là họ đã quyết định không cung cấp bản vá, vì vậy bạn phải chờ phiên bản 6.2. Tôi đã báo cáo vấn đề SQLite liên kết với bài đăng này, vì vậy hy vọng họ có thể thay đổi ý định của họ.

Một tùy chọn khác là báo cáo sự cố với phát triển SQLite và chờ một bản sửa lỗi từ đó. Trong cả hai trường hợp, bạn phải đợi bản sửa lỗi ở bên SQLite hoặc EF6. Lưu ý rằng vấn đề có thể tái sản xuất ngay cả với bộ khởi tạo chuẩn MigrateDatabaseToLatestVersion.

tôi đã có thể workaround nó bằng cách sử dụng như sau xấu xí phản ánh hack:

public override void InitializeDatabase(T context) 
{ 
    base.InitializeDatabase(context); 

    var _historyRepository = migrator.GetType().GetField("_historyRepository", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(migrator); 
    var _existingConnection = _historyRepository.GetType().BaseType.GetField("_existingConnection", BindingFlags.Instance | BindingFlags.NonPublic); 
    _existingConnection.SetValue(_historyRepository, null); 

    var x = migrator.GetPendingMigrations(); 
    if (x.Any()) 
    { 
     migrator.Update(); 
     Seed(context); 
    } 
} 

Trường hợp ngoại lệ ban đầu đã biến mất, nhưng bây giờ tôi nhận được một số khác nói 'Không MigrationSqlGenerator tìm thấy cho nhà cung cấp' System. Data.SQLite '. Sử dụng phương thức SetSqlGenerator trong lớp cấu hình di trú đích để đăng ký các trình tạo SQL bổ sung. ' mà tôi nghĩ là một vấn đề khác liên quan đến việc thiếu MigrationSqlGenerator trong các dịch vụ EF SQLite. Nó có thể hoặc có thể không phải là một vấn đề tùy thuộc vào cách bạn đã giải quyết điều đó trong 6.1.3.

Dù sao, tôi sẽ không khuyên bạn sử dụng hack ở trên. Hãy chờ đợi sửa lỗi hoặc hạ cấp xuống 6.1.3 ngay bây giờ.

Các vấn đề liên quan