3

I'm using the following code to create a Berkeley DB but I'm receiving an error on the last line:

The type initializer for 'BerkeleyDB.Internal.libdb_csharpPINVOKE' threw an exception.

Code:

Dim DB As DatabaseEnvironment
Dim Config As DatabaseEnvironmentConfig

Config = New DatabaseEnvironmentConfig
Config.Create = True

DB = DatabaseEnvironment.Open("d:\database.db", Config)

Does anyone know what I am doing wrong please ?

I'm using VB Express 2010 with the .Net Framework 4.0

Full Stack :

System.TypeInitializationException: The type initializer for 'BerkeleyDB.Internal.libdb_csharpPINVOKE' threw an exception. ---> 
System.TypeInitializationException: The type initializer for 'SWIGStringHelper' threw an exception. 
System.DllNotFoundException: Unable to load DLL 'libdb_csharp61': Le module spécifié est introuvable. 
(Exception from HRESULT: 0x8007007E) at BerkeleyDB.Internal.libdb_csharpPINVOKE.SWIGStringHelper.SWIGRegisterStringCallback_libdb_csharp(SWIGStringDelegate stringDelegate)
at BerkeleyDB.Internal.libdb_csharpPINVOKE.SWIGStringHelper..cctor() 
in C:\carol\db-6.1.23\lang\csharp\src\Internal\libdb_csharpPINVOKE.cs:line 29     
--- End of inner exception stack trace ---     
at BerkeleyDB.Internal.libdb_csharpPINVOKE.SWIGStringHelper..ctor()     
at BerkeleyDB.Internal.libdb_csharpPINVOKE..cctor() 
in C:\carol\db-6.1.23\lang\csharp\src\Internal\libdb_csharpPINVOKE.cs:line 33     
--- End of inner exception stack trace ---     
at BerkeleyDB.Internal.libdb_csharpPINVOKE.new_DB_ENV(UInt32 jarg1)     
at BerkeleyDB.Internal.DB_ENV..ctor(UInt32 flags) 
in C:\carol\db-6.1.23\lang\csharp\src\Internal\DB_ENV.cs:line 276     
at BerkeleyDB.DatabaseEnvironment..ctor(UInt32 flags) 
in C:\carol\db-6.1.23\lang\csharp\src\DatabaseEnvironment.cs:line 174     
at BerkeleyDB.DatabaseEnvironment.Open(String home, DatabaseEnvironmentConfig cfg) 
in C:\carol\db-6.1.23\lang\csharp\src\DatabaseEnvironment.cs:line 2705     
at WindowsApplication1.Form1.Form1_Load(Object sender, EventArgs e) 
in C:\Documents and Settings\Steven\Local Settings\Application Data\Temporary Projects\WindowsApplication1\Form1.vb:line 13"
  • The account running this has access to the folder? – Brian Mains Jun 07 '15 at 01:33
  • 2
    Whenever you ask about an unhandled exception, you should post the full exception. You can do that by copying it to the clipboard in the debugger, or if you're not using the debugger, you can (temporarily) put a try/catch around your code: `try {/* your code */} catch (Exception ex) {Console.WriteLine(ex.ToString()); Console.ReadLine();throw;}` or use `MessageBox.Show(ex.ToString())` or the equivalent. Just post the result of `ex.ToString()`. – John Saunders Jun 07 '15 at 01:33
  • I added the full stack. – Youssef Mellouki Jun 07 '15 at 09:44
  • So you can see that your error is "Unable to load DLL 'libdb_csharp61': Le module spécifié est introuvable. " – John Saunders Jun 10 '15 at 21:16

1 Answers1

1
  1. Make sure your .net project is set to .NET 4.0
  2. Build as x86
  3. libdb_csharp61.dll is in your /bin/debug folder
Inga
  • 482
  • 4
  • 9