Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run after click once install throws type initializer exception for SQLiteApiWin32Internal #158

Closed
brianhanline opened this issue Mar 31, 2015 · 4 comments

Comments

@brianhanline
Copy link

I am using SQLite PCL in a portable class lib as part of a WPF desktop application.

When I run the program in debug from visual studio everything works perfectly.

If I just copy the contents of the bin directory to the target platform and run by just double clicking on the .exe, everything works perfectly.

BUT. If I publish as a click once application, install with click once on the target platform, and run, SQLite PCL throws the following exception. If I build my own setup and deployment project, deploy, and run, I also get this exception.

System.TypeInitializationException: The type initializer for 'SQLite.Net.Platform.Win32.SQLiteApiWin32Internal' threw an exception. ---> System.Exception: Failed to load native sqlite library
at SQLite.Net.Platform.Win32.SQLiteApiWin32Internal..cctor()
--- End of inner exception stack trace ---
at SQLite.Net.Platform.Win32.SQLiteApiWin32Internal.sqlite3_open_v2(Byte[] filename, IntPtr& db, Int32 flags, IntPtr zvfs)
at SQLite.Net.Platform.Win32.SQLiteApiWin32.Open(Byte[] filename, IDbHandle& db, Int32 flags, IntPtr zvfs)
at SQLite.Net.SQLiteConnection..ctor(ISQLitePlatform sqlitePlatform, String databasePath, SQLiteOpenFlags openFlags, Boolean storeDateTimeAsTicks, IBlobSerializer serializer, IDictionary2 extraTypeMappings) at SQLite.Net.SQLiteConnection..ctor(ISQLitePlatform sqlitePlatform, String databasePath, Boolean storeDateTimeAsTicks, IBlobSerializer serializer, IDictionary2 extraTypeMappings)
at Wni.Core.ViewModels.EmployeeViewModel.OpenDBConnection()
at Wni.Core.ViewModels.EmployeeViewModel.OnLoadedCommand()

@oysteinkrog
Copy link
Owner

Seems like the sqlite binaries are not loaded properly.
I've never used clickonce so I don't know how it works..
The Win32 platform includes sqlite binaries as content files (so check that they are deployed correctly).
These binaries are preloaded for the correct cpu configuration (x86/x64) using some path logic + LoadLibrary.
I suggest you look at SQLiteApiWin32Internal() and try to see how that code could go wrong, given how the clickonce installer deploys the files.

@brianhanline
Copy link
Author

Thanks for the hint. It led me to the problem and solution. I didn't need to look at the code.

Others may find a better solution but here is what I did.

I ran winmerge against the visual studio bin folder versus the click-once deployment folder. That yielded nothing until I included subfolders. Then I discovered the obvious. The SQLite interop files for x86 and x64 were missing from the deployment. Specifically: x64\SQLite.Interop.dll and x86\SQLite.Interop.dll.

I went back to visual studio. I created new solution folders for x86 and x64. I copied the interop files from the bin folder into the new solution folders. I INCLUDED THEM IN THE PROJECT AS CONTENT AND SET THE "Copy to Output Directory" PROPERTY TO "Copy If Newer" for each. That caused the click-once publisher to include them in the deployment AND to put them in the correct relative path.

I deployed and executed. Everything worked fine.

Thanks!!

@brianhanline
Copy link
Author

... Oops.

This sentence:

"I created new solution folders for x86 and x64. I copied the interop files from the bin folder into the new solution folders."

is better stated:

"I created new PROJECT folders for x86 and x64. I created the project folders in the project that click-once deploys. That is, the project that produces the executable. I copied the interop files from the bin folder into the new solution folders."

@nathando
Copy link

nathando commented Oct 3, 2016

@brianhanline: thank you! Encountered the exact same problem, solved it with your suggestion. Still bug me which dependency the Interop dll belong to though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants