Skip to content

Behavior of System.ComponentModel.Win32Exception.HResult does not match documentation #5252

@jhudsoncedaron

Description

@jhudsoncedaron

dotnet/runtime#46829 (comment)

Description

(new System.ComponentModel.Win32Exception(0x50)).HResult.ToString("X") output 0x80004005. From the documentation of Exception.HResult: we get "The HRESULT value" and "Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception."

Spent some time debugging this before managing to reduce it to Win32Exception. The expected value this would have had from the documentation is 80070050 but it got 80004005. Either the documentation is wrong or the code is wrong. Bug has probably always existed. I can currently trace it as far back as existing in .NET Framework 4.0. Bug still exists in .NET 5.

Configuration

All .NET Versions. All OSes.

Regression?

No

Other Information

It may or may not be a bug in .NET Core but it's not going to get fixed so the documentation should be updated. See linked issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3Indicates issues/PRs that are low priorityarea-System.ComponentModeluntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions