EntryPointNotFoundException in SQLite after displaying FolderBrowserDialog

前端 未结 2 1456
梦谈多话
梦谈多话 2020-12-19 17:09

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

Unable to find an entry point named \'sqlite3_ch

相关标签:
2条回答
  • 2020-12-19 17:11

    I had the same issue when I used GMAP.NET, which appeared to be opening an SQLite connection using an older version. Then, when I attempted to open a connection with the newer version, the error with SQLite.Interop.dll occurred.

    By opening a dummy connection with the newer version before instantiating the GMAP.NET object using the older connection, the error went away. The connection doesn't have to do anything, it just has to be opened first.

    using (SQLiteConnection con = new SQLiteConnection("Data Source=" + dat + ";Version=3;"))
    {
        con.Open();
    }
    
    0 讨论(0)
  • 2020-12-19 17:24

    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.

    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.

    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.

    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>
    

    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.

    0 讨论(0)
提交回复
热议问题