System.Data.SQLite
View Ticket
Not logged in
Ticket UUID: da685c0bacca97c43bde3f00c7f03d3b4ecf1ac5
Title: GetXmlConfigFileName should check for invalid directory
Status: Closed Type: Code_Defect
Severity: Important Priority: Medium
Subsystem: Native_Library_PreLoader Resolution: Fixed
Last Modified: 2016-03-09 13:58:43
Version Found In: 1.0.99
User Comments:
anonymous added on 2016-03-08 21:26:54:

When bundling the System.Data.Sqlite libraries using something like Costura.Fody, the code to retrieve the Xml configuration file repeatedly fails since the directory of the assembly cannot be determined. The trace output has many messages like:

Native library pre-loader failed to get setting "No_PreLoadSQLite" value: System.ArgumentNullException: Value cannot be null.
Parameter name: path1
   at System.IO.Path.Combine(String path1, String path2)
   at System.Data.SQLite.UnsafeNativeMethods.GetXmlConfigFileName()
   at System.Data.SQLite.UnsafeNativeMethods.GetSettingValue(String name, String default)

Since UnsafeNativeMethods.GetAssemblyDirectory can return null in several code paths, UnsafeNativeMethods.GetXmlConfigFileName should check for null before passing the path to Path.Combine. This would avoid many repeated null reference exceptions.


mistachkin added on 2016-03-08 23:12:07:
The set of circumstances where the directory value can be null is extremely
small.  Is this issue on the .NET Compact Framework?

Meanwhile, I'm working the fix now.  There does not appear to be an easy way
to test it.  Are you able to confirm the fix in your environment?

mistachkin added on 2016-03-08 23:17:16:
Candidate fix on trunk, please let us know if it works to resolve the issue in
your environment.

mistachkin added on 2016-03-09 02:39:28:
Test added by check-in [2b1ca5ca01d6ddb6].

anonymous added on 2016-03-09 13:58:43:

That fix worked; I no longer see the exceptions being thrown. Thanks for such a quick turn-around, I hope to see the fix in 1.0.100!

I agree there are a small number of scenarios were it would be null, but I'm in one of them now. I'm using Costura to embed the System.Data.SQLite assemblies into my assembly to make distribution of it easier. This tutorial gives an example of doing this.

Costura works by embedding dependent assemblies as resources, then when they need to be resolved they are extracted as streams and loaded via Assembly.Load (see this link for the code). Since the assembly comes from a stream, it has no location on disk and so GetAssemblyDirectory returns null.