Closed NN--- closed 7 years ago
I'm unclear what you're actually asking for here. What code in PInvoke are you suggesting should set this value?
If within an Exception type that we define, there would be no reason to use reflection to call SetErrorCode
as all it does is set the HResult
property, which has a protected setter (so derived types can call it).
If the purpose to have same behavior with .NET then this change is not needed.
The System.ComponentModel.Win32Exception has "_HResult" field which is not updated accordingly to Win32 error code. There is call to SetErrorCode in several cases for predefined codes but not for the Win32 codes. I don't know why the code in .NET doesn't do this while this is super useful.
I suggest to call this internal function via reflection and have the correct HResult value.