How can I set the InnerException property of an Exception object, while I’m in the constructor of that object? This boils down to finding and setting the backing field of a property that has no setter.
BTW: I have seen this evain.net – Getting the field backing a property using Reflection but looking for non IL-based solution, if possible.
The constructor of Exception is the place where the Exception type is created, so I cannot call it using the base class constructor MyException() :base(...) etc.
Why can’t you just call the constructor taking the InnerException as a parameter? If for some reason it’s not possible, the backing field in System.Exception is:
I found it out using Redgate’s Reflector. Using reflection I suppose you could set the inner exception.
Edit: In most cases it’s not a good idea to access private fields via reflection, but I don’t know enough about NT’s case to know for sure if it’s a good or bad idea.