c# - 将 sqlite3 数据库复制到用户文件夹并加载数据库导致应用程序在 WACK 验证期间无法启动
问题描述
当用户第一次运行应用程序时,我的应用程序将 sqlite3 数据库复制到用户文件夹
using System;
using System.Collections;
using SQLitePCL;
//....
public sealed partial class MainPage
{
SQLiteConnection db;
private void onLoaded(object sender, RoutedEventArgs e)
{
createEditableCopyOfDatabaseIfNeeded();//remove this line
}
public async void createEditableCopyOfDatabaseIfNeeded()
{
StorageFolder aFolder = await StorageFolder.GetFolderFromPathAsync(ApplicationData.Current.LocalFolder.Path);
if (await aFolder.TryGetItemAsync("app.data") != null)
{
db = new SQLiteConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path, "app.data"));
}
else
{
var afile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/app.data"));
if (afile != null)
{
try
{
if(await afile.CopyAsync(ApplicationData.Current.LocalFolder, "app.data") != null)
{
db = new SQLiteConnection(Path.Combine(ApplicationData.Current.LocalFolder.Path, "app.data"));
}
}
catch (Exception)
{
}
}
}
}
}
此代码适用于我的 PC,但如果我使用 WACK 验证,则报告无法启动应用程序。
如果我删除线
createEditableCopyOfDatabaseIfNeeded();
该应用程序可以通过 WACK 并启动,但无法正常工作(数据库未打开)。
后来,我发现
if(await afile.CopyAsync(ApplicationData.Current.LocalFolder, "app.data") != null)
导致应用程序无法启动,即使我将“app.data”更改为一个小尺寸的 png 文件,它仍然无法正常工作,这意味着该功能
CopyAsync导致应用程序无法在 WACK 中启动
-------------------------------------------------WACK error report
failed Platform version launch
Cannot launch App
The app failed platform version launch test.
failed App launch
Cannot launch App
failed Crashes and hangs
Executable myapp.exe was detected by Windows Error Reporting and experienced a crash or hang.
Application was detected by Windows Error Reporting and experienced a crash or hang.
Crash dump file myapp.exe.1016.dmp was created by Windows Error Reporting and provides additional information.
Crash dump file myapp.exe.12440.dmp was created by Windows Error Reporting and provides additional information.
----------------------------------------------
欢迎您的意见
解决方案
推荐阅读
- javascript - 如何使用 jquery 或 javascript 以 HTML 形式显示本地存储数据?
- c# - 如何在 FluentValidation 中返回整个模型的键
- ios - 从容器播放视频
- javascript - 我们可以从文本中间搜索正则表达式吗?
- regex - 正则表达式确定文件名中的 YYYYMMDD 模式
- angular - Angular Build 失败
- c++ - 如何让 BOOST_FOREACH 使用不可复制的右值?
- google-app-maker - Google App Maker 无法重新识别自己的一些小部件
- java - ZonedDateTime 忽略 ss 部分的 00
- angularjs - 我正在尝试将数据从自定义角度 JS 服务返回到控制器,但它总是返回“{}”