Table 仅在真实设备上没有 (public) 列
Table has no (public) columns only on real device
我有最简单的应用程序,我想在我全神贯注之前在我的设备上试用它们。但是,当我 运行 在我的 iPhone 上(与我的 macbook 上的模拟器相对)时,我收到了最奇怪的错误消息。
Table has no (public) columns .
我正在使用 SQLite.Net PCL 并且我是从 git 集线器构建它的,因为我遇到了一些问题,因为它没有 IOS 的平台 dll,否则.
相关代码。
在我的模型中我有这个:
public class Setting
{
[PrimaryKey, AutoIncrement]
public long Id { get; set; }
[Indexed]
public string Key { get; set; }
public string Value { get; set; }
}
抛出此错误消息的代码很简单:
using (SQLiteConnection db = GetCon ()) {
db.CreateTable<Setting> ();
}
但在我看来,最奇怪的是这段代码在模拟器上运行良好,但在 iphone 本身上使应用程序崩溃。
如果有人有一些想法那就太好了。
编辑:
此错误是在 SQLite.Net-PCL 库的 this file 行 380 上引发的,但 仅在设备上 而不是在模拟器上引发。
对于其他可能关心此问题的人,我找到了问题的答案。问题在于 Type 没有任何属性(所讨论的类型是简单模型 class)。我知道那是垃圾,我发现以下链接提供了更多信息,我将在此 post 中涉及这些链接,以防链接失效:
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)
我暂时将其取消链接,但是,我会在发布前尝试让链接器忽略这些 classes。感谢您的帮助。
我发现我的问题只是一个(不是那么微妙的)编程错误。我正在使用 TypeInfo class 并想使用 Sqlite Connection 方法:
CreateTable (Type type);
我手上有一个 TypeInfo 实例,我需要将其转换回 System.Type。我不小心不小心使用了 GetType() 方法而不是 AsType() 方法,当你想到它时,这是显而易见的。我在异常消息和 OP 消息中得到的线索是 does System.Runtime have public properties?
var type = table.TypeInfo.AsType();
// var type = table.TypeInfo.GetType(); *WRONG*
connection.CreateTable(type);
我有最简单的应用程序,我想在我全神贯注之前在我的设备上试用它们。但是,当我 运行 在我的 iPhone 上(与我的 macbook 上的模拟器相对)时,我收到了最奇怪的错误消息。
Table has no (public) columns .
我正在使用 SQLite.Net PCL 并且我是从 git 集线器构建它的,因为我遇到了一些问题,因为它没有 IOS 的平台 dll,否则.
相关代码。
在我的模型中我有这个:
public class Setting
{
[PrimaryKey, AutoIncrement]
public long Id { get; set; }
[Indexed]
public string Key { get; set; }
public string Value { get; set; }
}
抛出此错误消息的代码很简单:
using (SQLiteConnection db = GetCon ()) {
db.CreateTable<Setting> ();
}
但在我看来,最奇怪的是这段代码在模拟器上运行良好,但在 iphone 本身上使应用程序崩溃。
如果有人有一些想法那就太好了。
编辑: 此错误是在 SQLite.Net-PCL 库的 this file 行 380 上引发的,但 仅在设备上 而不是在模拟器上引发。
对于其他可能关心此问题的人,我找到了问题的答案。问题在于 Type 没有任何属性(所讨论的类型是简单模型 class)。我知道那是垃圾,我发现以下链接提供了更多信息,我将在此 post 中涉及这些链接,以防链接失效:
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)
我暂时将其取消链接,但是,我会在发布前尝试让链接器忽略这些 classes。感谢您的帮助。
我发现我的问题只是一个(不是那么微妙的)编程错误。我正在使用 TypeInfo class 并想使用 Sqlite Connection 方法:
CreateTable (Type type);
我手上有一个 TypeInfo 实例,我需要将其转换回 System.Type。我不小心不小心使用了 GetType() 方法而不是 AsType() 方法,当你想到它时,这是显而易见的。我在异常消息和 OP 消息中得到的线索是 does System.Runtime have public properties?
var type = table.TypeInfo.AsType();
// var type = table.TypeInfo.GetType(); *WRONG*
connection.CreateTable(type);