Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 1.50 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Visual Studio does not show the original location of rethrown inner exception in C#
  2. // Inside DpmEntrypoint static class.
  3. public static object Invoke(Delegate d, object[] args)
  4. {
  5.     try
  6.     {
  7.         // Invoke directly if not networked.
  8.         if (LocalNode.Singleton == null)
  9.             return d.DynamicInvoke(args);
  10.  
  11.         // Get the network name of the object and the name of the method.
  12.         string objectName = (d.Target as ITransparent).NetworkName;
  13.         string methodName = d.Method.Name;
  14.  
  15.         // Get our local node and invoke the method.
  16.         return LocalNode.Singleton.Invoke(objectName, methodName, args);
  17.    }
  18.    catch (Exception ex)
  19.    {
  20.         ex.Rethrow();
  21.         return null;
  22.     }
  23. }
  24.  
  25. // Inside ExceptionExtensions static class.
  26. public static void Rethrow(this Exception ex)
  27. {
  28.     if (ex is TargetInvocationException)
  29.         ex.InnerException.Rethrow();
  30.     else
  31.     {
  32.         typeof(Exception).GetMethod("PrepForRemoting",
  33.             BindingFlags.NonPublic | BindingFlags.Instance)
  34.             .Invoke(ex, new object[0]);
  35.         throw ex;
  36.     }
  37. }
  38.        
  39. namespace Rethrow {
  40.     [System::Runtime::CompilerServices::Extension]
  41.     public ref class ExceptionExtensions abstract sealed
  42.     {
  43.     public:
  44.         [System::Runtime::CompilerServices::Extension]
  45.         static void Rethrow(System::Exception^ s)
  46.         {
  47.             std::rethrow_exception(std::copy_exception<System::Exception^>(s));
  48.             throw;
  49.         }
  50.     };
  51. }
  52.        
  53. catch (Exception ex)
  54. {
  55.     throw;
  56.     return null;
  57. }