I get this error when I use the function value_EXPAND_SZ:
std.stdio.writefln(key.getValue("").value_EXPAND_SZ());
This is caused because the value returned is 2 characters too long.
The function value_EXPAND_SZ use the function ExpandEnvironmentStringsA. In the documentation found here: http://msdn2.microsoft.com/en-us/library/ms724265.aspx, this function return the string length, plus terminating null character, plus one.
This means that the variable "newValue" returned by value_EXPAND_SZ contains 2 extra characters.
To resolve the bug, I changed the last line by:
return newValue[0 .. newValue.length - 2];