2017-11-16 7 views
9

तक नहीं पहुंच सकता है, मैं SQLite के साथ काम कर रहा हूं। मैं समस्याओं के बिना मेरी WPF आवेदन में इकाई की रूपरेखा 6.1.3 का उपयोग करने में सक्षम हूँ, लेकिन जब मैं यह 6.2.0 मैं निम्न त्रुटि प्राप्त करने के लिए अद्यतन:ईएफ 6.1.3 से EF 6.2.0 को अपडेट करने से किसी डिस्पोजेड ऑब्जेक्ट त्रुटि

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"... 

कोई भी विचार?

+0

कृपया हमें 'CRUD_On_Pipe' और 'GetAll' के लिए स्रोत कोड दिखाएं। – mjwills

+0

@mjwills हां मैंने ऐप और परीक्षण परियोजनाओं दोनों को अद्यतन किया था। – ferit

+0

@mjwills ने उन स्रोत कोडों के साथ प्रश्न अपडेट किया। – ferit

उत्तर

5

समस्या SQLiteConnection वर्ग (बजाय ConnectionState.Closed लौटने जब निपटाए वस्तु पर कहा जाता है की ObjectDisposedException फेंक) द्वारा RepositoryBase वर्ग और गलत (IMO) IDbConnection.State संपत्ति के कार्यान्वयन में एक परिवर्तन के कारण होता है।

यह #398: NullReferenceException on Code First Migrations when Glimpse is installed में रिपोर्ट जैसा ही है। स्थिति के अनुसार, यह पहले ही ईएफ 6 भंडार में तय हो चुका है, लेकिन दुर्भाग्य से उन्होंने पैच प्रदान करने का फैसला नहीं किया है, इसलिए आपको v6.3 की प्रतीक्षा करनी है। मैंने पहले से ही इस पोस्ट से जुड़ी SQLite समस्या की सूचना दी है, इसलिए उम्मीद है कि वे अपना दिमाग बदल सकते हैं।

एक और विकल्प SQLite विकास को इस मुद्दे की रिपोर्ट करना और वहां से एक फिक्स का इंतजार करना है। दोनों मामलों में, आपको SQLite या EF6 पक्ष में किसी फ़िक्स के लिए प्रतीक्षा करनी होगी। ध्यान दें कि समस्या मानक MigrateDatabaseToLatestVersion प्रारंभकर्ता के साथ भी पुन: उत्पन्न होती है।

मैं निम्नलिखित बदसूरत प्रतिबिंब हैक का उपयोग करके इसे वैकल्पिक हल करने में सक्षम था:

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); 
    } 
} 

मूल अपवाद चला गया है, लेकिन अब मैं एक और एक सिस्टम 'नहीं MigrationSqlGenerator प्रदाता के लिए मिल गया' कहने हो रही है। Data.SQLite '। अतिरिक्त SQL जेनरेटर पंजीकृत करने के लिए लक्ष्य माइग्रेशन कॉन्फ़िगरेशन क्लास में SetSqlGenerator विधि का उपयोग करें। ' जो मुझे लगता है कि SQLite EF सेवाओं में MigrationSqlGenerator की कमी से संबंधित एक अलग समस्या है। 6.1.3 में आप इसे कैसे हल करते हैं, यह एक समस्या हो सकती है या नहीं भी हो सकती है।

वैसे भी, मैं उपरोक्त हैक का उपयोग करने की अनुशंसा नहीं करता। या तो फॉक्स फिक्स का इंतजार करें या अभी 6.1.3 पर डाउनग्रेड करें।

संबंधित मुद्दे