应用程序崩溃只在iOS上使用SQLite PCL进行更新.适用于Android.有人有主意吗?
我的SQLite NuGet
在App.SqliteConnection.Update(pAssetRecovery)崩溃
public static async Task Update(Models.Model_AssetRecovery pAssetRecovery)
{
try
{
await Task.Run(() => App.SqliteConnection.Update(pAssetRecovery));
}
catch (SystemException ex)
{}
}
Run Code Online (Sandbox Code Playgroud)
模型被保存
[Table("tblAssetRecovery")]
public class Model_AssetRecovery : _Model_Base
{
[PrimaryKey, NotNull, Unique]
public string strAssetRecoveryID { get; set; }
public string strAssignmentID { get; set; }
public string strAssetID { get; set; }
public int intAssignmentIdentity { get; set; }
public int intCurrentPage { get; set; }
public int intRecoveryUsersID { get; set; }
public string strDebtorAddressID { get; set; }
public string strRecoveryAddress1 { get; set; }
public string strRecoveryAddress2 { get; set; }
public string strRecoveryCity { get; set; }
public string strRecoveryZipcode { get; set; }
public string strRecoveryLongitude { get; set; }
public string strRecoveryLatitude { get; set; }
public int intRecoveryStateID { get; set; }
public int intRecoveryCountryID { get; set; }
public string strRecoveryDate { get; set; }
public TimeSpan tspanRecoveryTime { get; set; }
public string strRecoveryNotificationAgency { get; set; }
public string strRecoveryNotificationPhone { get; set; }
public string strRecoveryNotificationDate { get; set; }
public TimeSpan tspanRecoveryNotificationTime { get; set; }
public string strRecoveryNotificationNote { get; set; }
public string strRecoveryNotificaitonAddress1 { get; set; }
public string strRecoveryNotificaitonAddress2 { get; set; }
public string strRecoveryNotificaitonCity { get; set; }
public string strRecoveryNotificaitonZipCode { get; set; }
public string strDMVInfo { get; set; }
public string strRecoveryNotificaitonCounty { get; set; }
public int intRecoveryNotificationStateID { get; set; }
public string strAssetRecoveryParagraph { get; set; }
public int intTowDollyUsed { get; set; }
public int intIsLPRRecovery { get; set; }
public string strAssetColor { get; set; }
public int intAssetYear { get; set; }
public string strAssetMake { get; set; }
public string strAssetModel { get; set; }
public string strAssetVIN { get; set; }
public string strAssetBodyStyle { get; set; }
public int intRecoveryAddressSource { get; set; }
public int intRecoveryAddressType { get; set; }
public string strCounty { get; set; }
public int intStorageLotID { get; set; }
public int intKeysObtained { get; set; }
public int intKeysPlanToObtain { get; set; }
public int intKeysObtainedSource { get; set; }
public int intOdometerReading { get; set; }
public int intOdometerType { get; set; }
public string strCompletionMessage { get; set; }
public int intAccessToInterior { get; set; }
public int intIsAssetDamaged { get; set; }
public int intAirbagsDeployed { get; set; }
public int? intVehicleLicenseStateID { get; set; }
public string strPlateNumber { get; set; }
public int intAssignmentType { get; set; }
public int intAssignmentStatus { get; set; }
public int intLPRProvider { get; set; }
public int intCanYouRecordMileage { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
iOS DI SQLiteHandler
class SQLite_iOS : ISQLiteConnection
{
public SQLiteConnection GetConnection()
{
try
{
var sqliteFilename = "MyApp.db3";
string documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); // Documents folder
string libraryPath = Path.Combine(documentsPath, "..", "Library"); // Library folder
var path = Path.Combine(libraryPath, sqliteFilename);
// Create the connection
var plat = new SQLite.Net.Platform.XamarinIOS.SQLitePlatformIOS();
var conn = new SQLite.Net.SQLiteConnection(plat, path);
// Return the database connection
return conn;
}
catch (SystemException ex)
{
namespace.Classes.Helpers.Helper_ErrorHandling.SendErrorToServer(ex, "GetConnection_iOS", "GetConnection_iOS");
//Device.BeginInvokeOnMainThread(() => App.iAppNavigation.GetErrorPage());
return null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
Visual Studio错误
2015-05-15 16:47:19.775 namespace[4678:182349] critical: Stacktrace:
2015-05-15 16:47:19.789 namespace[4678:182349] critical: at <unknown> <0xffffffff>
2015-05-15 16:47:19.789 namespace[4678:182349] critical: at (wrapper managed-to-native) SQLite.Net.Platform.XamarinIOS.SQLiteApiIOSInternal.sqlite3_prepare_v2 (intptr,string,int,intptr&,intptr) <IL 0x00028, 0xffffffff>
2015-05-15 16:47:19.789 namespace[4678:182349] critical: at SQLite.Net.Platform.XamarinIOS.SQLiteApiIOS.Prepare2 (SQLite.Net.Interop.IDbHandle,string) <IL 0x0001c, 0x00190>
2015-05-15 16:47:19.790 namespace[4678:182349] critical: at SQLite.Net.SQLiteCommand.Prepare () <IL 0x0001c, 0x000e5>
2015-05-15 16:47:19.790 namespace[4678:182349] critical: at SQLite.Net.SQLiteCommand.ExecuteNonQuery () <IL 0x00017, 0x000db>
2015-05-15 16:47:19.790 namespace[4678:182349] critical: at SQLite.Net.SQLiteConnection.Execute (string,object[]) <IL
0x00044, 0x00214>
2015-05-15 16:47:19.790 namespace[4678:182349] critical: at SQLite.Net.SQLiteConnection.Update (object,System.Type) <IL 0x00104, 0x00b58>
2015-05-15 16:47:19.791 namespace[4678:182349] critical: at SQLite.Net.SQLiteConnection.Update (object) <IL 0x0000d, 0x000e2>
2015-05-15 16:47:19.791 namespace[4678:182349] critical: at namespace.Classes.Helpers.SQLite.Helper_SQLite_AssetRecovery/<>c__DisplayClass9.<Update>b__7 () [0x00000] in d:\LocalRepository\namespace\namespace\namespace\Classes\Helpers\SQLite\Helper_SQLite_AssetRecovery.cs:32
2015-05-15 16:47:19.791 namespace[4678:182349] critical: at System.Threading.Tasks.Task`1<int>.InnerInvoke () [0x00012] in /Users/builder/data/lanes/1503/6481535e/source/mono/external/referencesource/mscorlib/system/threading/Tasks/Future.cs:686
2015-05-15 16:47:19.791 namespace[4678:182349] critical: at System.Threading
.Tasks.Task.Execute () [0x00016] in /Users/builder/data/lanes/1503/6481535e/source/mono/external/referencesource/mscorlib/system/threading/Tasks/Task.cs:2523
2015-05-15 16:47:19.792 namespace[4678:182349] critical: at System.Threading.Tasks.Task.ExecutionContextCallback (object) [0x00007] in /Users
/builder/data/lanes/1503/6481535e/source/mono/external/referencesource/mscorlib/system/threading/Tasks/Task.cs:2887
2015-05-15 16:47:19.792 namespace[4678:182349] critical: at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object) [0x00027] in /Users/builder/data/lanes/1503/6481535e/source/mono/mcs/class/corlib/System.Threading/ExecutionContext.cs:242
2015-05-15 16:47:19.792 namespace[4678:182349] critical: at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext,System.Threading.ContextCallback,object,bool) [0x00000] in /Users/builder/data/lanes/1503/6481535e/source/mono/mcs/class/corlib/System.Threading/ExecutionContext.cs:228
2015-05-15 16:47:19.793 namespace[4678:182349] critical: at System.Threading.Tasks.Task.ExecuteWithThreadLocal (System.Threading.Tasks.Task&) [0x0005f] in /Users/builder/data/lanes/1503/6481535e/source/mono/external/referencesource/mscorlib/system/threading/
Tasks/Task.cs:2848
2015-05-15 16:47:19.793 namespace[4678:182349] critical: at System.Threading.Tasks.Task.ExecuteEntry (bool) [0x0006f] in /Users/builder/data/lanes/1503/6481535e/source/mono/external/referencesource/mscorlib/system/threading/Tasks/Task.cs:2781
2015-05-15 16:47:19.793 namespace[4678:182349] critical: at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in /Users/builder/data/lanes/1503/6481535e/source/mono/external/referencesource/mscorlib/system/threading/Tasks/Task.cs:2728
2015-05-15 16:47:19.794 namespace[4678:182349] critical: at System.Threading.ThreadPool.<UnsafeQueueCustomWorkItem>m__0 (object) [0x00000] in /Users/builder/data/lanes/1503/6481535e/source/mono/mcs/class/corlib/System.Threading/ThreadPool.cs:258
2015-05-15 16:47:19.794 namespace[4678:182349] critical: at (wrapper runtime-invoke) <Module>.runtime_invoke_void__this___object (object,intptr,intptr,intptr) <IL 0x00062, 0xffffffff>
2015-05-15 16:47:19.794 namespace[4678:182349] critical:
Native stacktrace:
2015-05-15 16:47:19.795 namespace[4678:182349] critical:
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================
Run Code Online (Sandbox Code Playgroud)
活动日志
<entry>
<record>1054</record>
<time>2015/05/15 23:29:58.111</time>
<type>Error</type>
<source>Editor or Editor Extension</source>
<description>System.InvalidCastException: Unable to cast object of type 'Xamarin.VisualStudio.Debugger.AD7DocumentContext' to type 'Microsoft.VisualStudio.Debugger.Interop.IDebugDocumentContext2'.
 at System.StubHelpers.InterfaceMarshaler.ConvertToManaged(IntPtr pUnk, IntPtr itfMT, IntPtr classMT, Int32 flags)
 at Microsoft.VisualStudio.Debugger.Interop.IDebugStackFrame2.GetDocumentContext(IDebugDocumentContext2& ppCxt)
 at Microsoft.VisualStudio.Debugger.Parallel.Common.DocumentContext.GetFileNameAndPath()
 at Microsoft.VisualStudio.Debugger.Parallel.UI.ThreadMarkerGenerator.LocationMatchesTagger(DocumentContext location, MarkerTagger tagger)
 at Microsoft.VisualStudio.Debugger.Parallel.UI.ThreadMarkerGenerator.<>c__DisplayClass1.<GetMarkersForTagger>b__0(ThreadMarker marker)
 at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
 at Microsoft.VisualStudio.Debugger.Parallel.Extension.MarkerTagger.<GenerateTagList>d__a.MoveNext()
 at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
 at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
 at Microsoft.VisualStudio.Debugger.Parallel.Extension.MarkerTagger..ctor(ITextBuffer buffer, ITextDocument document)
 at Microsoft.VisualStudio.Debugger.Parallel.Extension.MarkerTaggerProvider.CreateTagger[T](ITextBuffer buffer)
 at Microsoft.VisualStudio.Text.Tagging.Implementation.TagAggregator`1.GatherTaggers(ITextBuffer textBuffer)</description>
</entry>
</activity>
Run Code Online (Sandbox Code Playgroud)
kir*_*tab 12
我知道你的问题已经过了很多时间,但它是我能找到类似问题的少数几个地方之一(比如我的),所以我只是想分享一下我的案例解决了什么.
问题:
我在使用来自不同线程的数据库连接的不同方法中获得异常,这让我相信iOS中的SQLite由于某种原因不是线程安全的,比如Android和WinRT(我使用相同的代码,它有一些锁和互斥但使用延迟查询的方法在锁定释放后导致问题).
所以修复它的是在连接构造函数中使用附加参数来启用SQLite的线程安全性(或者至少这是我认为发生的事情:))
解决方案:
var connection = new SQLiteConnection(
new SQLite.Net.Platform.XamarinIOS.SQLitePlatformIOS(),
sqliteFilename,
openFlags: SQLiteOpenFlags.ReadWrite|SQLiteOpenFlags.FullMutex|SQLiteOpenFlags.Create,
storeDateTimeAsTicks: true);
Run Code Online (Sandbox Code Playgroud)
这里重要的是标志 - 我认为默认情况下在iOS中不启用FullMutex与Android和WinRT不同
希望它能帮助别人,并为所有人提供快乐的编码;)
归档时间: |
|
查看次数: |
1339 次 |
最近记录: |