16

I have the simplest of apps that I thought I would try on my device before I got too engrossed. However, I am getting the strangest error message when I run it on my iPhone (as apposed to the the emulator on my macbook).

Table has no (public) columns .

I am using the SQLite.Net PCL and I have built it from git hub as I had some problems with it not having the platform dlls for IOS otherwise.

Relevant code.

In my models I have this:

public class Setting
{
    [PrimaryKey, AutoIncrement]
    public long Id { get; set; }

    [Indexed]
    public string Key { get; set; }

    public string Value { get; set; }

}

The code that throws this error message is the simple:

using (SQLiteConnection db = GetCon ()) {

            db.CreateTable<Setting> ();
}

but in my opinion the strangest thing is that this code works fine on the emulator but crashes the application on the iphone itself.

If anyone has some ideas that would be great.

EDIT: This error is thrown on the SQLite.Net-PCL library on this file line 380 but only on the device and not on the emulator.

Jack
  • 10,943
  • 13
  • 50
  • 65
Daniel Casserly
  • 3,552
  • 2
  • 29
  • 60
  • How do you get this message? Is this an exception? If so, can you post the stack trace? – Grisha May 06 '15 at 06:45
  • It is an error, unfortunately on the device in xamarin studio I cannot get the error to stay on screen for very long before it stops execution of the program. Probably a bug in the program, however having looked through the code, that inner exception is thrown in the sqlite-net library which I will link in the question (when github comes back online). @Grisha – Daniel Casserly May 06 '15 at 11:51
  • @DanielCasserly the fact that it works on the your mac and not the device might have to do with it actually being a *Simulator* instead of a real *emulator*. You mention that you built it yourself instead of using the Nuget, perhaps the problem lies there, what issue did you have using it otherwise? And how are passing in the platform specific connection? – Jack May 08 '15 at 15:13
  • @Jack the problem with the nuget package was that the Xamarin.Platforms solutions weren't being loaded in, therefore I just got the Github code and built it myself. So why would it work on the simulator and not the device? (I usually find it the other way round tbh)? – Daniel Casserly May 08 '15 at 15:29
  • @DanielCasserly You probably want to use some sort of dependeny injection to load the platform. For example `var platform = Xamarin.Forms.DependencyService.Get ().GetConnection();`. Regarding the simulator, it probably comes down to that simulator is only *simulating* the software of the device and not the hardware. – Jack May 08 '15 at 15:41
  • @Jack thanks for your help. I found the issue was with the linker being on and therefore removing the properties of the class at runtime on the device. Strange but true. Thanks again. – Daniel Casserly May 08 '15 at 18:02

2 Answers2

10

For others to whom this may concern, I found the answer to my problem. The issue was with the Type not having any properties (the type in question the simple model class). Knowing that to be rubbish I found the following links that gave more information which I will relate in this post in case the links go dead:

Type.GetProperties returning nothing

NOTE: Be careful with assembly linker

If you're building with linker enabled you may need to use the class somewhere, so it will not be ripped off at compile time. Sometimes, only instantiating the class in your code is not enough, the linker may detect that the instance is never used and will remove it anyway.

http://developer.xamarin.com/guides/ios/advanced_topics/linker/

The linking process can be customized via the linker behavior drop-down in Project Options. To access this double-click on the iOS project and browse to iOS Build > Linker Options, as illustrated below (see link for details)

I have for now left it to be unlinked, however, I will try before release to get the linker to ignore these classes. Thanks for all your help.

Community
  • 1
  • 1
Daniel Casserly
  • 3,552
  • 2
  • 29
  • 60
  • I think that issue has more to do with the release configuration then the fact that it is a device (I'm just guessing that you used a different configuration for the device). – Jack May 08 '15 at 18:05
  • @Jack not really the configuration is exactly the same. I think the simulator ignores the linking settings tbh. – Daniel Casserly May 08 '15 at 18:06
  • OK I thought that was the case because on android I encountered the same problem but there it was only in the release configuration. – Jack May 08 '15 at 18:07
  • Thank you! I was having an issue where sqlite couldn't find my class nor the Get methods on some attributes. Simply using the get methods for each attribute in the table fixed the issue. I wish there were a way to disable how it strips those out though. – SMKS Nov 07 '16 at 18:23
0

I found my problem was just a (not that subtle) programming error. I was working with the TypeInfo class and wanted to use the Sqlite Connection method:

 CreateTable (Type type);

What I had in my hand was a TypeInfo instance which I needed to convert back to the System.Type. I accidentally without thinking used the GetType() method instead of AsType() method which is obvious when you think about it. The clue I got was in the exception message along with the OP message was does System.Runtime have public properties?

var type = table.TypeInfo.AsType();
// var type = table.TypeInfo.GetType(); *WRONG*
connection.CreateTable(type);
The Senator
  • 5,181
  • 2
  • 34
  • 49
  • I have been facing this issue with message _does User have public properties?_ and it was because User class was missing access modifier. So I set it to public and this error stopped raising. Hope it helps someone! – Sergi Mascaró Jun 15 '19 at 14:08