3

I had a user control with Sqlite. After Compiled and Added to the Tool Box, by dragging it into a new Form,an Error Message as described Below:

"Failed to Create Component 'UserControl1'. The Error Message follows 'System.DllNotFoundException: 'Unable to Load Dll 'Sqlite.Interop.dll' : The Specified Module could not be found. Exception from HResult: 0x8007007E

I googled on this subject, I'm still unable to resolved this issue. But the funny parts is If I hard coded it in the Form by reference and create a new control, the user control worked. Why Drag and Drop had this problem?

One more Question: I'm using Nuget to install sqlite, there are 2 version: 32 and 64 bit: which one should i add as reference? I'm using VS2010 ultimate sp1. Sqlite v 1.0.83.0. Compiled dll as any cpu.

chriga
  • 798
  • 2
  • 12
  • 29
SimonOngsk
  • 121
  • 1
  • 4
  • 12
  • The error message is probably stating the exact problem: it cannot find `Sqlite.Interop.dll`. Compare your hard-coded code with the code that the form designer generates. – Robert Harvey Jan 02 '13 at 04:51
  • this might help: http://system.data.sqlite.org/index.html/tktview?name=54e52d4c6f – codingbiz Jan 02 '13 at 04:51
  • Also check this link: http://mdetras.com/2011/09/29/unable-to-load-dll-sqlite-interop-dll/ – codingbiz Jan 02 '13 at 04:58
  • I viewed the above 2 link before posted this. The User control was created using WindowLibrary, I added the dll to the toolbox, but I would not be able to use. If I used the added reference from the project explorer and hard-coded it, it work (add the component into the control "this.Add(XXX)", so the dll is there and worked! But.. Why not from the ToolBox? – SimonOngsk Jan 02 '13 at 06:32

2 Answers2

1

If you download correct binary for SQLite then copy SQLite.Interop.dll into your Release or Debug folder according to your project build option.

Elshan
  • 7,339
  • 4
  • 71
  • 106
1

I think this is an issue separate from SQLite and more specifically deals with the DLL not being found when you try to drag the user control from the Toolbox. I had the same problem. I was able to programmatically add the user control via Controls.Add(myUserControl) and it worked fine but I couldn't drag it from the Toolbox. Some searching led me to the following link with insight from Hans Passant:

https://social.msdn.microsoft.com/Forums/en-US/e6ba24f2-4f2d-42bd-b2f2-1e00744e0052/dllimport-throws-systemdllnotfoundexception-in-usercontrol?forum=netfxbcl

The gist is that the Designer doesn't know the path for where to look for the DLL. As a test, I hard-coded the path within DllImport i.e. [DllImport(*full path here*)], and I was able to successfully drag the user control from the Toolbox to the Designer. (Make sure you do a build after adding the full path before trying to add the user control!)

Without any major testing, it seems I was then able to then remove the fully qualified path and the Designer seemed to remember where to look. I could delete the user control from the form and add it again without issue. Once I closed Visual Studio and re-opened it, though, dragging and dropping the user control from the Toolbox failed again. Hopefully this information can help someone understand what's going on and/or lead them in the right direction for a solution.

VineAndBranches
  • 468
  • 3
  • 7