.Net 4.5 vs .Net 3.5 RegSetValueEx returns empty null characters

I recently encountered a problem with RegSetValueEx (from advapi32.dll). It looks like REG_SZ saved with this method in .Net 3.5 is not read correctly in .Net 4.5 with RegistryKey.GetValue (). Illustration below:

//---.Net 3.5--- (no issues)
Call RegSetValueEx() to save base64 string value "ajG8s" to the registry
Call RegistryKey.GetValue() on that value returns "ajG8s"

//---.Net 4.5--- (no issues)
Call RegSetValueEx() to save base64 string value "ajG8s" to the registry
Call RegistryKey.GetValue() on that value returns "ajG8s"

//---.Net 3.5 & .Net 4.5--- (issues)
Call RegSetValueEx() to save base64 string value "ajG8s" to the registry (in .Net 3.5)
Call RegistryKey.GetValue() on that value returns "ajG8s\0\0\0\0\0\6\A\z./,'./Z?" (in .Net 4.5)

The code is 100% the same as the examples above - just switch .Net 4.5 version.

Initially, I thought that perhaps the line being written to the registry was not correctly terminated by zero - this is so. I also confirmed that this does not happen if I try to write a value using RegistryKey.SetValue () - it looks like it is calling RegSetValueEx (from advapi32.dll).

( 4.5) . , .

, ? !

0
1

, . base64 WinApi RegSetValueEx() - length , .

- () :

RegistryKey.GetValue()

.Net 3.5 4.5. .Net 3.5 GetValue() '\ 0',.Net 4.5 GetValue() , ... - . "".Net - , ! - node.

, - :)

0

All Articles