[U8.1] Sqlite异常:在Win10上运行的Win8.1应用程序中的运行时组件 [英] [U8.1]Sqlite Exception: Runtime component in Win8.1 app running on Win10

查看:80
本文介绍了[U8.1] Sqlite异常:在Win10上运行的Win8.1应用程序中的运行时组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个利基,所以我想知道是否有人可能对此问题有任何见解:

This is a bit of a niche, so I'm wondering if anyone might have any insight into this issue:

我的项目在Windows 8.1中包含sqlite代码运行时组件。它使用来自nuget的C#sqlite-net包装器(所有公共接口都切换到内部)。

My project has sqlite code contained inside a Windows 8.1 Runtime Component. It is using the C# sqlite-net wrapper from nuget (with all the public interfaces switched to internal).

当我添加运行时组件作为对Win8.1应用程序(手机)的引用时和桌面)并在Win8.1操作系统上运行,sqlite代码工作正常。我还尝试添加运行时组件作为对Win10 UWP应用程序的引用,它也可以在Win10 OS上正常运行。

When I add the runtime component as a reference to a Win8.1 app (phone and desktop) and run it on Win8.1 OS, the sqlite code works fine. I also tried adding the runtime component as a reference to a Win10 UWP app and it runs fine on Win10 OS as well.

但是,我在运行时组件中遇到了sqlite代码的异常当我在 Win10操作系统中运行
Win8.1手机应用时。奇怪的是,如果我在Win8.1应用程序中对运行时组件执行相同的操作
,那么sqlite代码工作正常。

However, I encounter an exception with the sqlite code inside the runtime component when I run the Win8.1 Phone app in a Win10 OS. Oddly, if I do the same operation outside of the runtime component in my Win8.1 app, the sqlite code works fine.

在其他在Win10上运行Win8.1手机应用程序的话:

In other words, with an Win8.1 Phone app running on Win10:

//App.xaml.cs
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
     StorageFolder localFolder = ApplicationData.Current.LocalFolder;
     var outsideFolder = localFolder.CreateFolderAsync("outsideRT", CreationCollisionOption.OpenIfExists).AsTask().Result;
     var insideFolder = localFolder.CreateFolderAsync("insideRT", CreationCollisionOption.OpenIfExists).AsTask().Result;
     
     string outsidePath = Path.Combine(outsideFolder.Path, "db.sqlite");
     string insidePath = Path.Combine(insideFolder.Path, "db.sqlite");
       
     var databaseConnection = new SQLiteConnection(outsidePath , true); //works

     Component.CreateDB(insidePath); // fails
}

//Win8.1 Runtime Component
Component.cs
public static void CreateDB(string path)
{
     var databaseConnection = new SQLiteConnection(path, true); // exception
}

抛出异常:

" System.InvalidOperationException:句柄未初始化。

  at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)

 在System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDll(String unmanagedDllName,IntPtr gchManagedAssemblyLoadContext)

 在WinRTSQLite.SQLite3.SetDirectory(UInt32 directoryType,String directoryPath)

 在WinRTSQLite.SQLiteConnection..ctor(String databasePath,SQLiteOpenFlags openFlags,Boolean storeDateTimeAsTicks)\\\\ n 在WinRTSQLite.SQLiteConnection..ctor(S"

"System.InvalidOperationException: Handle is not initialized.
  at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
  at System.Runtime.Loader.AssemblyLoadContext.ResolveUnmanagedDll(String unmanagedDllName, IntPtr gchManagedAssemblyLoadContext)
  at WinRTSQLite.SQLite3.SetDirectory(UInt32 directoryType, String directoryPath)
  at WinRTSQLite.SQLiteConnection..ctor(String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks)\r\n   at WinRTSQLite.SQLiteConnection..ctor(S"

值得注意的是 Win8.1桌面应用程序中的相同代码
上运行 Win10操作系统工作正常。从Win8.1手机中的运行时组件调用sqlite代码似乎有些问题?

Worth noting is that the same code inside a Win8.1 Desktop app running on Win10 OS works fine. It just seems to have some issue executing sqlite code when it is called from a runtime component in Win8.1 Phone?

非常感谢任何见解!

谢谢。

推荐答案

嗨lewong,

Hi lewong,

>>我在运行时遇到运行时组件内的sqlite代码异常Win10操作系统中的Win8.1手机应用程序

>>I encounter an exception with the sqlite code inside the runtime component when I run the Win8.1 Phone app in a Win10 OS

您的意思是在Windows 10 Mobile上运行WP8.1应用程序吗?您的设备的操作系统版本是哪个?

Do you mean run WP8.1 app on Windows 10 Mobile? Which the OS version of your device?

>>它使用nuget的C#sqlite-net包装器(所有公共接口都切换到内部)

>>It is using the C# sqlite-net wrapper from nuget (with all the public interfaces switched to internal)

您使用的是哪个库?请上传您的演示版(OneDrive没问题),我们可以帮您缩小范围我们这方面的问题

Which library are you using? Could you please upload your demo(OneDrive is ok), we can help you to narrow down this issue on our sides


这篇关于[U8.1] Sqlite异常:在Win10上运行的Win8.1应用程序中的运行时组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆