
Untitled
By: a guest on
May 16th, 2012 | syntax:
None | size: 1.50 KB | hits: 11 | expires: Never
Visual Studio does not show the original location of rethrown inner exception in C#
// Inside DpmEntrypoint static class.
public static object Invoke(Delegate d, object[] args)
{
try
{
// Invoke directly if not networked.
if (LocalNode.Singleton == null)
return d.DynamicInvoke(args);
// Get the network name of the object and the name of the method.
string objectName = (d.Target as ITransparent).NetworkName;
string methodName = d.Method.Name;
// Get our local node and invoke the method.
return LocalNode.Singleton.Invoke(objectName, methodName, args);
}
catch (Exception ex)
{
ex.Rethrow();
return null;
}
}
// Inside ExceptionExtensions static class.
public static void Rethrow(this Exception ex)
{
if (ex is TargetInvocationException)
ex.InnerException.Rethrow();
else
{
typeof(Exception).GetMethod("PrepForRemoting",
BindingFlags.NonPublic | BindingFlags.Instance)
.Invoke(ex, new object[0]);
throw ex;
}
}
namespace Rethrow {
[System::Runtime::CompilerServices::Extension]
public ref class ExceptionExtensions abstract sealed
{
public:
[System::Runtime::CompilerServices::Extension]
static void Rethrow(System::Exception^ s)
{
std::rethrow_exception(std::copy_exception<System::Exception^>(s));
throw;
}
};
}
catch (Exception ex)
{
throw;
return null;
}