简体   繁体   中英

SQLite with RELEASE build of MonoTouch - Can't get PK?

I have been working with Monotouch and using the Debug build for the entire project. I recently changed it to release build to run it and it crashed on startup. Turning debug symbols on I found that the problem is SQLite is throwing a (bogus?) exception: "Can't update RealConfigData it has no PK!"

public class RealConfigData
{
    [AutoIncrement, PrimaryKey]
    public int Id { get; set; }
    // .. Other fields
}

public class GameData
{
    [AutoIncrement, PrimaryKey]
    public int Id { get; set; }

    public int Seed {get;set;}
    // .. Other fields
}

I'm getting an error when I try to .Insert() the first one in the database that RealConfigData has no PK! Yet, it does.

And with the 2nd one, I'm getting "Get Method not found for 'Seed'"

WTF, it seems like when compiled RELEASE, the metadata isn't there, or more accurately, isn't reliable... It seems like it found the PK for the 2nd class just fine, but couldn't for the first.. and then it couldn't find a getter for the field... this is crazy.

And This code works just fine when running debug.

What on Earth can possibly be wrong here?

I'm ready to release my iPhone app except for SQLite going down on me at the last minute. Help!

==== This was a misstatement:

Update: My other class that does not have a subclass works correctly! So it has something to do with the parent/child relationship.

This is not true, the exception was being eaten for that class.

Figured it out...

Found this: http://forums.xamarin.com/discussion/276/reflection-on-type-in-dll-allways-returns-propertyinfo-canwritefalse

Basically, you turn off the Link All Assemblies in the iOS Build settings if you want to have reflection work for properties. (Otherwise, it removes all the setters)

This could have taken me ages to figure out if I hadn't stumbled across that... :-(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM