If you get the error

System.IndexOutOfRangeException : Warning: A StringBuilder buffer has been overflowed by unmanaged code.  The process may become unstable.  Insufficient capacity allocated to the StringBuilder before marshaling it.
    at Ada.Cdf.Common.RegistryHelper.RegQueryValueExW(UIntPtr hKey, String lpValueName, Int32 lpReserved, UInt32& lpType, StringBuilder lpData, UInt32& lpcbData)

when reading a registry value, check the size of you´re string builder and the size of the RegQueryValueExW paramter lpcbData, these should be the same

uint size = BufferMaxLength;
uint type;
string keyValue = null;
StringBuilder keyBuffer = new StringBuilder(BufferMaxLength);
string keyname = "InstallLocation";

// Get the data from the registrykeyvalue
if (RegQueryValueExW(regKeyHandle, keyname, 0, out type, keyBuffer, ref size) != Success)
{
    throw new ApplicationException(string.Format(@"Could not find regstrykeyvalue [{0}\{1}]", regKeyPath, keyname));
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.