Question

I would like to develop a .tt template to generate POCOs from an SQLite database.

I use SharpDevelop 4.4.

Here's the .tt I have so far...

<#@ template hostspecific="true" language="C#" #>
<#@ output extension=".txt" #>
<#@ assembly name="System.Data" #>
<#@ assembly name="System.Data.SQLite" #>
<#@ import namespace="System.Data" #>
<#@ import namespace="System.Data.SQLite" #>
<#@ import namespace="System.IO" #>

<#
using (SQLiteConnection db = 
       new SQLiteConnection
            (string.Format("Data Source={0}", 
             Path.Combine(Path.GetDirectoryName(Host.TemplateFile), 
                          "Test.db"))))
{
    db.Open();
}
#>

I added the System.Data.SQLite.1.0.92.0 NuGet package to my project in order to have SQLite working.

When I run my template, I have have the following error:

Error running transform: System.DllNotFoundException: Unable to load DLL 'SQLite.Interop.dll': Le module spécifié est introuvable. (Exception from HRESULT: 0x8007007E)
   at System.Data.SQLite.UnsafeNativeMethods.sqlite3_config_none(SQLiteConfigOpsEnum op)
   at System.Data.SQLite.SQLite3.StaticIsInitialized()
   at System.Data.SQLite.SQLiteLog.Initialize()
   at System.Data.SQLite.SQLiteConnection..ctor(String connectionString, Boolean parseViaFramework)
   at System.Data.SQLite.SQLiteConnection..ctor(String connectionString)
   at Microsoft.VisualStudio.TextTemplating.GeneratedTextTransformation5e95cd16.TransformText()
   at Mono.TextTemplating.CompiledTemplate.Process()

Sorry for the french message... "Le module spécifié est introuvable" means "The specified module could not be found"...

Look like SharpDevelop managed to find the System.Data.SQLite.dll file from my project, but failed to find it's native counterpart SQLite.Interop.dll...

How could I make SharpDevelop find the DLL???

Any thoughts?

Once I figure out how to make SharpDevelop find the DLL and connect to my database, the rest of the template should be pretty straight forward to implement...

Thank you for your help!

Ghis

Was it helpful?

Solution 2

Thanks to @matt-ward input, I finally figured this out!

I used Process Monitor to find out where SharpDevelop was looking for the DLL.. Here's what I found...

C:\Users\ghigad\Projets\CS\TestT4\packages\System.Data.SQLite.Core.1.0.92.0\lib\net40\x86\SQLite.Interop.dll
C:\Users\ghigad\Projets\CS\TestT4\packages\System.Data.SQLite.Core.1.0.92.0\lib\net40\Win32\SQLite.Interop.dll
C:\Program Files (x86)\SharpDevelop\4.4\AddIns\Misc\TextTemplating\x86\SQLite.Interop.dll
C:\Program Files (x86)\SharpDevelop\4.4\AddIns\Misc\TextTemplating\Win32\SQLite.Interop.dll
C:\Program Files (x86)\SharpDevelop\4.4\ADDINS\MISC\TEXTTEMPLATING\SQLite.Interop.dll
C:\Program Files (x86)\SharpDevelop\4.4\AddIns\Misc\TextTemplating\x86\SQLite.Interop.dll
C:\Program Files (x86)\SharpDevelop\4.4\AddIns\Misc\TextTemplating\Win32\SQLite.Interop.dll
C:\Users\ghigad\Projets\CS\TestT4\packages\System.Data.SQLite.Core.1.0.92.0\lib\net40\x86\SQLite.Interop.dll
C:\Users\ghigad\Projets\CS\TestT4\packages\System.Data.SQLite.Core.1.0.92.0\lib\net40\Win32\SQLite.Interop.dll
C:\Program Files (x86)\SharpDevelop\4.4\AddIns\Misc\TextTemplating\x86\SQLite.Interop.dll
C:\Program Files (x86)\SharpDevelop\4.4\AddIns\Misc\TextTemplating\Win32\SQLite.Interop.dll
C:\Program Files (x86)\SharpDevelop\4.4\ADDINS\MISC\TEXTTEMPLATING\SQLite.Interop.dll
C:\Program Files (x86)\SharpDevelop\4.4\AddIns\Misc\TextTemplating\x86\SQLite.Interop.dll
C:\Program Files (x86)\SharpDevelop\4.4\AddIns\Misc\TextTemplating\Win32\SQLite.Interop.dll
C:\Users\ghigad\Projets\CS\TestT4\packages\System.Data.SQLite.Core.1.0.92.0\lib\net40\SQLite.Interop.dll
C:\Program Files (x86)\SharpDevelop\4.4\bin\SQLite.Interop.dll
C:\Windows\SYSWOW64\SQLite.Interop.dll
C:\Windows\system\SQLite.Interop.dll
C:\Windows\SQLite.Interop.dll
C:\Windows\SYSWOW64\SQLite.Interop.dll
C:\Program Files\Common Files\Microsoft Shared\Windows Live\SQLite.Interop.dll
C:\Program Files (x86)\COMMON FILES\MICROSOFT SHARED\Windows Live\SQLite.Interop.dll
C:\Program Files\Java\jdk1.6.0_30\bin\SQLite.Interop.dll
C:\Program Files\apache-ant-1.8.2\bin\SQLite.Interop.dll
C:\cygwin\bin\SQLite.Interop.dll
C:\Windows\SYSWOW64\SQLite.Interop.dll
C:\Windows\SQLite.Interop.dll
C:\Windows\SYSWOW64\wbem\SQLite.Interop.dll
C:\Windows\SYSWOW64\WindowsPowerShell\v1.0\SQLite.Interop.dll
C:\Program Files\Intel\WiFi\bin\SQLite.Interop.dll
C:\Program Files\Common Files\Intel\WirelessCommon\SQLite.Interop.dll
C:\Program Files (x86)\COMMON FILES\Roxio Shared\DLLShared\SQLite.Interop.dll
C:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\SQLite.Interop.dll
C:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\SQLite.Interop.dll
C:\Program Files (x86)\COMMON FILES\Roxio Shared\OEM\12.0\DLLShared\SQLite.Interop.dll
C:\Program Files (x86)\Roxio\OEM\AudioCore\SQLite.Interop.dll
C:\Program Files (x86)\MICROSOFT SQL SERVER\100\Tools\Binn\SQLite.Interop.dll
C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLite.Interop.dll
C:\Program Files\Microsoft SQL Server\100\DTS\Binn\SQLite.Interop.dll
C:\Program Files (x86)\MICROSOFT SQL SERVER\100\Tools\Binn\VSShell\Common7\IDE\SQLite.Interop.dll
C:\Program Files (x86)\MICROSOFT SQL SERVER\100\DTS\Binn\SQLite.Interop.dll
C:\Program Files\TortoiseSVN\bin\SQLite.Interop.dll
C:\Program Files (x86)\QuickTime\QTSystem\SQLite.Interop.dll
C:\Program Files (x86)\Windows Live\Shared\SQLite.Interop.dll

So, it turns out that quite a few directories are searched, then the contents of my PATH variable is used to search the file...

Matt's idea of putting the dll in SharpDevelop's bin directory would have worked, but I don't like the idea of saving files in the directory of an app... It would mean that I would have to copy the files over again if I ever update SharpDevelop to a newer version...

From the log, I guess copying the dll from .../packages/content/net40/x86 to .../packages/lib/net40/x86 would have also done the trick... Same thing here... If I fool around SQLite's Nuget package directory structure, everytime I'll check out my code from the source control or upgrade to a newer version, I'll have to copy the file again...

I finally decided to copy the DLL in a directory in C:\Program File (x86) and added it to my PATH.

Works great!

Thank you Matt for putting me on the right track!

OTHER TIPS

SharpDevelop will be finding your System.Data.SQLite.dll because your project will have a reference to it.

My first thoughts were:

For SQLite.Interop.dll you can either add a reference to it in your project or if you do not want to do that you can specify the path to the .dll. You should be able to do something like:

<#@ assembly name="$(SolutionDir)packages\System.Data.SQLite.Core.1.0.92.0\content\net45\x86\SQLite.Interop.dll" #>

Unfortunately this will not work since SQLite.Interop.dll is not an .NET assembly. So instead a workaround/hack would be to make the SQLite.Interop.dll available to SharpDevelop by putting it on the path. The easiest way is to copy it into SharpDevelop's bin folder:

C:\Program Files (x86)\SharpDevelop\4.4\bin
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top