dotnet / pinvoke

A library containing all P/Invoke code so you don't have to import it every time. Maintained and updated to support the latest Windows OS.
MIT License
2.12k stars 222 forks source link

Add NativeErrorCode in Win32Exception.Message #333

Closed NN--- closed 7 years ago

NN--- commented 7 years ago

Consider adding NativeErrorCode in the exception message. Greatly improves debugging and logs reading.

For instance

class Win32Exception
{
 // Return original Message with the code
 public override string Message => $"{base.Message} ({NativeErrorCode})";
}

Another option is to hack "_message" property to not store the same message twice and get free serialization.

AArnott commented 7 years ago

If this diverges from the behavior of Win32Exception on .NET Framework, that's not inline with the goal for this class. If Win32Exception behavior varies between platforms that can ultimately cause unexpected issues for consumers. So while I don't challenge the value that you're proposing, PInvoke's charter is not to improve on Win32Exception. We only implement it in the first place because PCL profiles don't define it themselves.