Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression with ReadFile and WriteFile for SafeHandle #1150

Closed
colejohnson66 opened this issue Feb 26, 2024 · 1 comment
Closed

Regression with ReadFile and WriteFile for SafeHandle #1150

colejohnson66 opened this issue Feb 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@colejohnson66
Copy link

Our project recently upgraded from 0.2.188 to 0.3.49. In doing so, ReadFile and WriteFile were changed from taking a SafeHandle to a raw HANDLE.

In 0.2.188, our invocation of ReadFile was:

if (PInvoke.ReadFile(_handle, ptr, (uint)buffer.Length, &bytesRead, overlapped))
    return (int)bytesRead;

In 0.3.49, we are now forced to do the dance that CsWin32 would previously do for us:

bool addedRef = false;
try
{
    // extract a HANDLE from the SafeFileHandle
    _handle.DangerousAddRef(ref addedRef);
    if (PInvoke.ReadFile((HANDLE)_handle.DangerousGetHandle(), ptr, (uint)buffer.Length, &bytesRead, overlapped))
        return (int)bytesRead;
}
finally
{
    _handle.DangerousRelease();
}

Context

  • CsWin32 version: 0.3.49-beta
  • Target Framework: net8.0
@colejohnson66 colejohnson66 added the bug Something isn't working label Feb 26, 2024
@colejohnson66
Copy link
Author

I see span overloads were added, so I will assume those are the recommended method of invocation now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant