dahall/Vanara

False-positive `IsNullOrEmpty` on `StrPtrAuto`

Closed this issue · 1 comments

Describe the bug and how to reproduce

When subscribing to service creation via AdvApi32.NotifyServiceStatusChange and AdvApi32.SERVICE_NOTIFY_FLAGS.SERVICE_NOTIFY_CREATED the returning structures pszServiceNames contains a false-positive IsNullOrEmpty even though the value is neither null nor empty. The IsNull check is okay, it returns false. But the check for string.Empty returns true, which leads to the false-positive. Checking for IsNull, then retrieving the string and checking the returned string for string.Empty myself gives the desired result.

What code is involved

private void HandleServiceStatusChange(IntPtr pParameter)
{
    AdvApi32.SERVICE_NOTIFY_2 serviceNotify = pParameter.ToStructure<AdvApi32.SERVICE_NOTIFY_2>();

    if (!serviceNotify.pszServiceNames.IsNullOrEmpty)
        Console.WriteLine(serviceNotify.pszServiceNames.ToString());
}

Expected behavior

Returning false on non-empty values.

Fixed for 4.0.1