c# - Recreate Exception on client side -
i have exact same problem in recreate exception serialized in json response, have managed instantiate correct type of exception:
public class serviceexceptiondata { public string type { get; set; } public string message { get; set; } public string errorcode { get; set; } public string stacktrace { get; set; } } ... private static void handleserviceexception(serviceexceptiondata serviceexception) { // exception type type t = type.gettype(serviceexception.type); // create exception instance var exceptioninstance = activator.createinstance(t); // set exception read-only properties: message, stacktrace ???
i tried lot of things set properties, here of them:
- can change private readonly field in c# using reflection?
- changing read properties reflection
- set object property using reflection
- is possible property's private setter through reflection?
- is simple way create method , set body dynamically in c#?
but doesn't work.
the exception's properties defined as:
public virtual string message { get; } public virtual string stacktrace { get; }
so there way set them once have exception instance (e.g. getting property's field , using setvaluedirect
) or should give , create derived class , override properties give them public setters?
Comments
Post a Comment