Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
Description of changes:
OpaqueError has two constructors :
OpaqueError(Exception ex) : base("OpaqueError:", ex) { this.obj = ex; }
OpaqueError(object obj) : base("Opaque obj is not an Exception.") { this.obj = obj;}
Unfortunately, overloading is resolved at compile time, so if you have an Exception currently cast to an Object, you get the second one, and therefore lose all the information in the original Exception.
Even more unfortunately, the thing that turns an extern's Error_Opaque into an OpaqueError does exactly that : casts the original Exception to an Object before use.
The solution is to change the second constructor to behave differently if the Object is really an Exception
OpaqueError(object obj)
: base(obj is Exception ? "OpaqueError:" : "Opaque obj is not an Exception.", obj as Exception)
{ this.obj = obj;}
"obj as Exception" is either an Exception, in which case we get back the context, or null, which is exactly the old behavior.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.