System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation
Ticket Hash: 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: (text/x-fossil-wiki)
When bundling the System.Data.Sqlite libraries using something like [https://github.com/Fody/Costura|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:

<pre>
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)
</pre>

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

mistachkin added on 2016-03-08 23:12:07: (text/x-fossil-plain)
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: (text/x-fossil-plain)
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: (text/x-fossil-plain)
Test added by check-in [2b1ca5ca01d6ddb6].

anonymous added on 2016-03-09 13:58:43: (text/x-fossil-wiki)
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.  [https://idmedia.no/general/including-sqlite-interop-dll-into-your-c-project|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 [https://github.com/Fody/Costura/blob/de81d0538dea4400efea82b428bcc2e4dd6be566/Template/ILTemplate.cs|this link] for the code).  Since the assembly comes from a stream, it has no location on disk and so <tt>GetAssemblyDirectory</tt> returns null.