[SQLite] System.Data.SQLite.SQLiteConnection cannot be cast to …

เวันนี้เขียนโปรแกรม C# กับ SQLite อยู่ดีๆ Bulid ผ่านะ แต่ Runtime Error โดยมี Message แจ้ง ดังนี้

[A]System.Data.SQLite.SQLiteConnection cannot be cast to [B]System.Data.SQLite.SQLiteConnection. Type A originates from 'System.Data.SQLite, Version=1.0.92.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' in the context 'Default' at location 'C:\Users\Chatr_000\Desktop\InvConfig(AutoRegisDLL)\InvConfig\bin\Release\System.Data.SQLite.dll'. Type B originates from 'System.Data.SQLite, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data.SQLite\v4.0_1.0.91.0__db937bc2d44ff139\System.Data.SQLite.dll'.

หลังจากไล่ Code อยู่นานพบว่าในเครื่องที่ใช้ Dev มี SQLite อยู่ 2 Version คือ 1.0.91.0 กับ 1.0.92.0 ติดตั้งอยู่ ซึ่งผมได้แก้ไขโดย

  • ถอนการติดตั้ง SQLite Version 1.0.91.0 ออกไป ซึ่งการอัพเกรด Version ของ SQLite DLL ควรทำการ Uninstall Version แก่ก่อนลง Version ใหม่เสมอ ครับ ถ้าไม่เอาออก Registry ของ Windows มันจะมองเป็น 2 Version
  • แก้ไขการโปรแกรมใหม่ ทั้งใน app config และ Reference ของ Project ให้ Reference ไปยังไฟล์ DLL ที่ถูก Version

Discover more from naiwaen@DebuggingSoft

Subscribe to get the latest posts to your email.