本文整理汇总了C#中System.Reflection.TargetInvocationException类的典型用法代码示例。如果您正苦于以下问题:C# TargetInvocationException类的具体用法?C# TargetInvocationException怎么用?C# TargetInvocationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TargetInvocationException类属于System.Reflection命名空间,在下文中一共展示了TargetInvocationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DontStripIfNoInnerException
public void DontStripIfNoInnerException()
{
TargetInvocationException wrapper = new TargetInvocationException(null);
List<Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList();
Assert.AreEqual(1, exceptions.Count);
Assert.Contains(wrapper, exceptions);
}
示例2: HandleTargetInvocationException
internal static void HandleTargetInvocationException(TargetInvocationException exception)
{
var innerException = exception.InnerException as SyncServiceException;
if (innerException != null)
{
throw new SyncServiceException(innerException.StatusCode, innerException.ErrorCode, innerException.Message, exception);
}
}
示例3: Inner
/// <summary>
/// Returns inner exception, while preserving the stack trace
/// </summary>
/// <param name="e">The target invocation exception to unwrap.</param>
/// <returns>inner exception</returns>
public static Exception Inner(TargetInvocationException e)
{
if (e == null) throw new ArgumentNullException("e");
if (null != InternalPreserveStackTraceMethod)
{
InternalPreserveStackTraceMethod.Invoke(e.InnerException, new object[0]);
}
return e.InnerException;
}
示例4: FailedTest
static void FailedTest(TargetInvocationException ex, ref int counter)
{
Console.ForegroundColor = GetColor(Colors.Failed);
Console.WriteLine(@"Failed");
Console.WriteLine(ex.InnerException.Message);
Console.ResetColor();
counter++;
}
示例5: EvaluateException
private void EvaluateException(bool expression, ExecuteParameters parameters, TargetInvocationException e)
{
if (expression) {
Processor.TestStatus.MarkRight(parameters.Cell);
}
else {
Processor.TestStatus.MarkWrong(parameters.Cell, "exception[" + e.InnerException.GetType().Name + ": \"" + e.InnerException.Message + "\"]");
}
}
示例6: RemoveWrapperExceptions
public void RemoveWrapperExceptions()
{
_client.RemoveWrapperExceptions(typeof(TargetInvocationException));
TargetInvocationException wrapper = new TargetInvocationException(_exception);
List<Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList();
Assert.AreEqual(1, exceptions.Count);
Assert.Contains(wrapper, exceptions);
}
示例7: GetRealExceptionWithStackTrace
public static Exception GetRealExceptionWithStackTrace(TargetInvocationException tiex)
{
var remoteStackTraceString = typeof(Exception).GetField("_remoteStackTraceString", BindingFlags.Instance | BindingFlags.NonPublic);
remoteStackTraceString.SetValue(
tiex.InnerException,
tiex.StackTrace + Environment.NewLine
);
return tiex.InnerException;
}
示例8: GetAdviceForUser_ReturnsIntroTextAsFirstLine_Always
public void GetAdviceForUser_ReturnsIntroTextAsFirstLine_Always()
{
var fileNotFoundException = new FileNotFoundException("message about missing styles", "dummyAssemblyStyles.dll");
var xamlParseException = new XamlParseException("", fileNotFoundException);
var targetInvocationException = new TargetInvocationException(xamlParseException);
var missingPreloadException = new MissingPreloadException("", targetInvocationException);
string adviceForUser = missingPreloadException.GetAdviceForUser();
string[] lines = adviceForUser.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
Assert.AreEqual(MissingPreloadException.IntroPartOfAdvice, lines[0]);
}
示例9: StripAggregateExceptionAndTargetInvocationException
public void StripAggregateExceptionAndTargetInvocationException()
{
_client.AddWrapperExceptions(typeof(AggregateException));
OutOfMemoryException exception2 = new OutOfMemoryException("Ran out of Int64s");
TargetInvocationException innerWrapper = new TargetInvocationException(exception2);
AggregateException wrapper = new AggregateException(_exception, innerWrapper);
List<Exception> exceptions = _client.ExposeStripWrapperExceptions(wrapper).ToList();
Assert.AreEqual(2, exceptions.Count);
Assert.Contains(_exception, exceptions);
Assert.Contains(exception2, exceptions);
}
示例10: Cozy
public static void Cozy()
{
Console.WriteLine("\n-----------------------------------------------");
Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName);
Console.WriteLine("-----------------------------------------------");
System.Exception e1 = new Exception();
System.ApplicationException e2 = new ApplicationException();
e2 = null;
System.Reflection.TargetInvocationException e3 = new TargetInvocationException(e1);
System.SystemException e4 = new SystemException();
e4 = null;
System.StackOverflowException e5 = new StackOverflowException();
e5 = null;
}
示例11: HandleSubscriberMethodException
/// <summary>
/// Handles a subscriber method exception by passing it to all extensions and re-throwing the inner exception in case that none of the
/// extensions handled it.
/// </summary>
/// <param name="targetInvocationException">The targetInvocationException.</param>
/// <param name="eventTopic">The event topic.</param>
protected void HandleSubscriberMethodException(TargetInvocationException targetInvocationException, IEventTopicInfo eventTopic)
{
Ensure.ArgumentNotNull(targetInvocationException, "targetInvocationException");
var innerException = targetInvocationException.InnerException;
innerException.PreserveStackTrace();
var context = new ExceptionHandlingContext();
this.ExtensionHost.ForEach(extension => extension.SubscriberExceptionOccurred(eventTopic, innerException, context));
if (!context.Handled)
{
throw innerException;
}
}
示例12: ResolveTargetInvocationException
public static Exception ResolveTargetInvocationException(TargetInvocationException ex)
{
if (SecurityManager.IsGranted(new ReflectionPermission(ReflectionPermissionFlag.MemberAccess)))
{
FieldInfo remoteStackTrace = typeof (Exception).GetField("_remoteStackTraceString",
BindingFlags.Instance | BindingFlags.NonPublic);
remoteStackTrace.SetValue(ex.InnerException, ex.InnerException.StackTrace + "\r\n");
return ex.InnerException;
}
else
{
return ex;
}
}
示例13: UnwrapTargetInvokationException
/// <summary>
/// Unwraps the TargetInvocationException that reflection methods helpfully give us.
/// </summary>
/// <param name="tie">Exception to unwrap</param>
/// <returns>A copy of the inner exception, for a few cases.</returns>
public static Exception UnwrapTargetInvokationException(TargetInvocationException tie)
{
if (tie.InnerException.GetType() == typeof(DataStoreCastException))
{
DataStoreCastException orig = (DataStoreCastException)tie.InnerException;
return new DataStoreCastException(orig.FromType, orig.ToType, tie);
}
else if (tie.InnerException.GetType() == typeof(DataNode.ValueNotInitialized))
{
DataNode.ValueNotInitialized orig = (DataNode.ValueNotInitialized)tie.InnerException;
throw new DataNode.ValueNotInitialized(orig.key, tie);
}
else if (tie.InnerException.GetType() == typeof(NotSupportedException))
{
NotSupportedException orig = (NotSupportedException)tie.InnerException;
throw new NotSupportedException(orig.Message, tie);
}
return null;
}
示例14: StripMultipleWrapperExceptions
public void StripMultipleWrapperExceptions()
{
HttpUnhandledException wrapper = new HttpUnhandledException("Something went wrong", _exception);
TargetInvocationException wrapper2 = new TargetInvocationException(wrapper);
RaygunMessage message = _client.CreateMessage(wrapper2);
Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
}
示例15: StripTargetInvocationExceptionByDefault
public void StripTargetInvocationExceptionByDefault()
{
TargetInvocationException wrapper = new TargetInvocationException(_exception);
RaygunMessage message = _client.CreateMessage(wrapper);
Assert.AreEqual("System.NullReferenceException", message.Details.Error.ClassName);
}