EntryPointNotFoundException在System.Data.SQLite显示的FolderBrowserDialog后 [英] EntryPointNotFoundException in System.Data.SQLite after displaying FolderBrowserDialog

查看:268
本文介绍了EntryPointNotFoundException在System.Data.SQLite显示的FolderBrowserDialog后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用64位程序System.Data.SQLite抛出以下EntryPointNotFoundException:

When using a 64-bit program System.Data.SQLite is throwing the following EntryPointNotFoundException:

无法找到DLL'SQLite.Interop.dll名为'sqlite3_changes_interop'的入口点。

Unable to find an entry point named 'sqlite3_changes_interop' in DLL 'SQLite.Interop.dll'.

奇怪的是它只发生如果外键= TRUE 指定在连接字符串中,更重要的是我只显示后,的FolderBrowserDialog 。我在浏览一个文件夹以显示数据库加载。

Strangely it only occurs if Foreign Keys=True is specified in the connection string and more importantly only after I display a FolderBrowserDialog. I was browsing for a folder to display databases to load.

下面code显示问题:

The following code displays the problem:

public Form1()
{
    InitializeComponent();

    // Exception below if this is displayed
    using (var diag = new FolderBrowserDialog())
    {
        diag.ShowDialog(this);
    }

    var conn = new SQLiteConnection("data source=':memory:'");
    conn.Open(); // Works fine
    conn.Close();

    // No exception below if displayed here instead
    //using (var diag = new FolderBrowserDialog())
    //{
    //    diag.ShowDialog(this);
    //}

    conn = new SQLiteConnection("data source=':memory:';foreign keys=True");
    conn.Open(); // EntryPointNotFoundException thrown here
    conn.Close();
}

打开与外键=连接真工作正常,如果对话框不显示或者如果它显示打开任何其他的SQLite连接后。在code。如果程序作为32位进程运行也能正常工作。该行为也是相同的,如果我使用任一单混合模式的x64 SQLite的组件或MSIL + x64的互操作程序集。我使用v1.0.92.0所以是没有问题的。

Opening the connection with foreign keys=True works fine if the dialog isn't shown or if it is shown after any other SQLite connection is opened. The code also works fine if the program runs as a 32-bit process. The behaviour is also the same if I use either the single mixed mode x64 SQLite assembly or the MSIL + x64 interop assembly. I'm using v1.0.92.0 so this is not the problem.

所以,问题是为什么会显示的FolderBrowserDialog 影响System.Data.SQLite装配发现在自己的互操作库的入口点,为什么会只发生在64位进程?

So the question is why would showing the FolderBrowserDialog affect the System.Data.SQLite assembly finding the entry point in its own interop library and why would it only occur in a 64-bit process?

作为一种解决办法,我可以做任何事情都要在程序之前加载在内存中的数据库,但我不喜欢这样的解决方案为我使用EF6,并希望能够使用通过配置不同的供应商一个配置文件,甚至在通过用户输入的运行时间。因此,所有的sqlite的具体code是在另一个程序集。

As a work around I can load an in-memory database before doing anything else in the program but I don't like this "solution" as I'm using EF6 and would like to be able to use different providers configured via a config file or even at runtime via user input. Hence all the sqlite specific code is in another assembly.

推荐答案

System.Data.SQLite 的较旧版本的显示的FolderBrowserDialog 。如果有安装在计算机则显示任何的通用对话框,其中包括浏览器都将导致这些扩展组件加载到应用程序的 AppDomain中的任何shell /浏览器扩展

An older version of System.Data.SQLite is being loaded when displaying the FolderBrowserDialog. If there are any shell / explorer extensions installed on the computer then displaying any of the common dialogs which includes Explorer will cause assemblies from those extensions to be loaded into the application's AppDomain.

在的情况下, System.Data.SQLite 本机库被加载(<$ C C $> SQLite.Interop.dll )导致大会所有加载​​的版本使用该版本的本机库。加载程序集的新版本首先使被加载本地库的新版本。这还导致了多个版本的程序集被加载到AppDomain中,虽然,这意味着,外壳扩展将使用一个不同的版本比他们的期望。

In the case of System.Data.SQLite a native library is loaded (SQLite.Interop.dll) resulting in all loaded versions of the assembly to use that version of the native library. Loading the new version of the assembly first causes the new version of the native library to be loaded. This still results in multiple versions of the assembly being loaded in the AppDomain though and it means that shell extensions will be using a different version than they expect.

我尝试在不同的AppDomain打开的的FolderBrowserDialog ,但仍然导致组件被加载到应用程序的正常AppDomain中。我已经开了一个错误的<一个href="https://connect.microsoft.com/VisualStudio/feedback/details/871790/displaying-a-commondialog-which-displays-a-file-explorer-can-load-assemblies-into-the-applications-appdomain"相对=nofollow>微软连接关于这一点,但我不是太乐观,这将是固定的。

I tried opening the the FolderBrowserDialog in a different AppDomain but it still results in assemblies being loaded into the application's normal AppDomain. I've opened a bug on Microsoft connect regarding this but I'm not too hopeful that it will be fixed.

作为一种解决办法我把这个添加到我的app.config:

As a workaround I've added this to my app.config:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="System.Data.SQLite"
                        version="1.0.92.0"
                        publicKeyToken="DB937BC2D44FF139"
                        language="neutral"
                        processorArchitecture="msil" />
      <bindingRedirect oldVersion="0.0.0.0-1.0.91.65535" newVersion="1.0.92.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

这将导致 System.Data.SQLite 的只有一个版本被加载。它确实还意味着外壳扩展将使用错误的版本,因此可能会抛出异常。

This results in only the single version of System.Data.SQLite being loaded. It does still mean that shell extensions will be using the wrong version and hence could potentially throw exceptions.

这篇关于EntryPointNotFoundException在System.Data.SQLite显示的FolderBrowserDialog后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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