Skip to content

Commit

Permalink
Fixes #23
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgios Diamantopoulos committed Aug 20, 2013
1 parent 2efcf70 commit 0fbfea6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions CLAP/ParserRunner.cs
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.Serialization;
using CLAP.Interception;

#if !FW2
Expand Down Expand Up @@ -184,6 +185,7 @@ private int RunInternal(string[] args, object obj)
}
catch (TargetInvocationException tex)
{
PreserveStackTrace(tex.InnerException);
verbException = tex.InnerException;
}
catch (Exception ex)
Expand Down Expand Up @@ -213,6 +215,19 @@ private int RunInternal(string[] args, object obj)
return verbException == null ? MultiParser.SuccessCode : MultiParser.ErrorCode;
}

static void PreserveStackTrace(Exception e)
{
var ctx = new StreamingContext(StreamingContextStates.CrossAppDomain);
var mgr = new ObjectManager(null, ctx);
var si = new SerializationInfo(e.GetType(), new FormatterConverter());

e.GetObjectData(si, ctx);
mgr.RegisterObject(e, 1, si); // prepare for SetObjectData
mgr.DoFixups(); // ObjectManager calls SetObjectData

// voila, e is unmodified save for _remoteStackTraceString
}

private void PostInterception(
object target,
Method method,
Expand Down

0 comments on commit 0fbfea6

Please sign in to comment.