I'm having the following error in my application, using Xamarin in Android: SQLite.SQLiteException: duplicate column name IdSettings.
Here is my code:
private Database()
{
this.connection = new SQLiteConnection(DatabasePath);
this.Connection.CreateTable<Settings>();
this.Connection.CreateTable<Profile>();
this.Connection.CreateTable<Stat>();
this.Connection.CreateTable<Crest>();
this.Connection.CreateTable<MatchTeam>();
this.Connection.CreateTable<Match>();
this.Connection.CreateTable<Media>();
this.Connection.CreateTable<DbInfo>();
}
And here is the stack trace from Android:
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
... 1 more
Caused by: md52ce486a14f4bcd95899665e9d932190b.JavaProxyThrowable: SQLite.SQLiteException: duplicate column name: IdSettings
at SQLite.SQLite3.Prepare2 (SQLitePCL.sqlite3 db, System.String query) [0x0001e] in <filename unknown>:0
at SQLite.SQLiteCommand.Prepare () [0x00011] in <filename unknown>:0
at SQLite.SQLiteCommand.ExecuteNonQuery () [0x00012] in <filename unknown>:0
at SQLite.SQLiteConnection.Execute (System.String query, System.Object[] args) [0x00040] in <filename unknown>:0
at SQLite.SQLiteConnection.MigrateTable (SQLite.TableMapping map) [0x000db] in <filename unknown>:0
at SQLite.SQLiteConnection.CreateTable (System.Type ty, CreateFlags createFlags) [0x00176] in <filename unknown>:0
at SQLite.SQLiteConnection.CreateTable[T](CreateFlags createFlags) [0x00000] in <filename unknown>:0
at FifaSeasons.Entities.Database..ctor () [0x0001d] in <filename unknown>:0
at FifaSeasons.Entities.Database.get_Instance () [0x00022] in <filename unknown>:0
at FifaSeasons.Entities.Settings.Load () [0x00000] in <filename unknown>:0
at FifaSeasons.App..ctor () [0x00006] in <filename unknown>:0
at FifaSeasons.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x00023] in <filename unknown>:0
at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (IntPtr jnienv, IntPtr native__this, IntPtr native_savedInstanceState) [0x00011] in <filename unknown>:0
at (wrapper dynamic-method) System.Object:77f7d68d-0e63-4fa1-ba05-91ac6f4e8d28 (intptr,intptr,intptr)
at md57f9709086b0c248507ed1071a2b22cc2.MainActivity.n_onCreate(Native Method)
at md57f9709086b0c248507ed1071a2b22cc2.MainActivity.onCreate(MainActivity.java:28)
at android.app.Activity.performCreate(Activity.java:6021)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2284)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1309)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5354)
... 4 more
This occurs in the first run of the application, and I think that the method MigrateTable should not run.
I'm also getting the same error with a very simple class
Problem solved!
In Android Options, I set linker to Sdk Assemblies Only.
Thanks for the suggestion newtoncw, but setting Sdk Assemblies Only was not an option for us. So I instead went with a Execute that will do an explicit CREATE Table. This works well on all platforms.
@masterjs how did you do that? Did you manually write out SQL queries?
I am seeing this issue still. Link SDK assemblies only works for me too, so there must be something we need to preserve in the linking.
This is still not a great solution but:
<AndroidLinkSkip>SQLite-net;SQLitePCL.raw</AndroidLinkSkip>
I will try adding the [Preserve] attribute to the assembly to help, but first I need to repro.
https://developer.xamarin.com/guides/ios/advanced_topics/linker/#Preserving_Code
Most helpful comment
I will try adding the
[Preserve]attribute to the assembly to help, but first I need to repro.https://developer.xamarin.com/guides/ios/advanced_topics/linker/#Preserving_Code