The problem you're describing seems to be related to a missed initialization call. If you have not opened a connection yet and try to deserialize, you need to initialize the library first.
You can use the following code to initialize the library:
khp("", -1); // initialise memory if not opening connection before allocation
ps: I do notice this was asked a year ago, hope my answer is helpful for anyone else running into the same issue and arriving here from a search.
Tel: +44 (0)28 3025 2242
Tel: +1 (212) 447 6700
Tel: +61 (0)2 9236 5700