c# – Cannot assign void to an implicitly-typed variable in Visual Studio 2026


I have the code below, which does not give any build error in Visual Studio 2022, but I get the following build error in Visual Studio 2026.

How can I fix this, or is this a bug in Visual Studio 2026?

I am getting the error on this line of code:

var provValue = registryValue.Split(',').Reverse();

The error message is:

Cannot assign void to an implicitly-typed variable

Here is the complete code:

string registryValue = "";
int registryType = 0;

if (valueData[1].StartsWith("\""))
{
    registryValue = valueData[1].Trim('"');
    registryType = (int)RegistryValueKind.String;
}
else
{
    var provVal = valueData[1].Split(new[] { ':' }, 2);

    switch (provVal[0])
    {
        case "dword":
            registryType = (int)RegistryValueKind.DWord;
            break;

        case "hex(7)":
            registryType = (int)RegistryValueKind.MultiString;
            break;

        case "hex(b)":
            registryType = (int)RegistryValueKind.QWord;
            break;

        case "hex(2)":
            registryType = (int)RegistryValueKind.ExpandString;
            break;

        case "hex":
            registryType = (int)RegistryValueKind.Binary;
            break;

        default:
            throw new Exception($"Invalid Registry type '{provVal[0]}'!");
    }

    while (provVal[1].EndsWith("\\"))
    {
        i++;
        provVal[1] = provVal[1].TrimEnd('\\');
        provVal[1] += fileLine[i].Trim();
    }

    registryValue = provVal[1];
}

switch ((RegistryValueKind)registryType)
{
    case RegistryValueKind.Binary:
        byte[] binValue = ConvertRegData(registryValue);
        childKey.SetValue(valueData[0], binValue, (RegistryValueKind)registryType);
        break;

    case RegistryValueKind.ExpandString:
        byte[] expByte = ConvertRegData(registryValue);
        string provExpString = Encoding.ASCII.GetString(expByte);
        provExpString = provExpString
            .Replace("\0\0", "/r/n")
            .Replace("\0", "")
            .Replace("/r/n", "\0");
        childKey.SetValue(valueData[0], provExpString, (RegistryValueKind)registryType);
        break;

    case RegistryValueKind.MultiString:
        byte[] multiByte = ConvertRegData(registryValue);
        string provMultString = Encoding.ASCII.GetString(multiByte);
        provMultString = provMultString.Replace("\0\0", "/r/n").Replace("\0", "");
        var multiString = provMultString
            .Split(new string[] { "/r/n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries)
            .ToArray();
        childKey.SetValue(valueData[0], multiString, (RegistryValueKind)registryType);
        break;

    case RegistryValueKind.DWord:
        int dValue = (int)Convert.ToUInt32(registryValue, 16);
        childKey.SetValue(valueData[0], dValue, (RegistryValueKind)registryType);
        break;

    case RegistryValueKind.QWord:
        var provValue = registryValue.Split(',').Reverse();
        registryValue = string.Join("", provValue);
        long qValue = (long)Convert.ToUInt64(registryValue, 16);
        childKey.SetValue(valueData[0], qValue, (RegistryValueKind)registryType);
        break;

    default:
        childKey.SetValue(valueData[0], registryValue, (RegistryValueKind)registryType);
        break;
}

Target framework: .NET 4.7.2
Visual Studio version: 18.1.1

Leave a Reply

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