C#/.NET application crashes(including Visual Studio) when trying to get the error message

5 views
Skip to first unread message

Martin van der Geer

unread,
Aug 20, 2015, 7:52:24 AM8/20/15
to hamsterdb User
I've made a really simple test application to put a few records in and trying to get them out. When I'm trying to get a record with a key which doesnt exist an exception is thrown. Well, its trying to. Within the DatabaseException class its trying to call:

[DllImport("hamsterdb-2.1.11.dll", EntryPoint = "ham_strerror",
  CallingConvention=CallingConvention.Cdecl)]
static public extern String StringError(int error);

This causes to crash the application or, when Visual Studio's debugger is attached, to hang Visual Studio (2013). Only way to end the Visual Studio process is to kill it via the task manager.

Any clue what I'm doing wrong??

The code I'm using:

byte[] data = db.Find(BitConverter.GetBytes((long)7000000)); //where 7000000 doesnt exist.

Christoph Rupp

unread,
Aug 20, 2015, 4:54:01 PM8/20/15
to hamster...@googlegroups.com
It's caused by a (buggy) marshalling of ham_strerror, which is called whenever an Exception is created. The exception is created because you look up a key wihch does not exist.

To fix this you can pull the "v2" branch and build the .NET DLL (you do not need to build the native DLL):
https://github.com/cruppstahl/hamsterdb/commits/v2

As a workaround you can also call db.TryFind which does not create an Exception if the key does not exist.

best regards
Christoph

--
You received this message because you are subscribed to the Google Groups "hamsterdb User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hamsterdb-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages