Skip to content

Preserves the stack trace when unwrapping TargetInvocationException #1443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/NHibernate/Async/Linq/DefaultQueryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected virtual async Task<object> ExecuteQueryAsync(NhLinqExpression nhLinqEx
}
catch (TargetInvocationException e)
{
throw e.InnerException;
throw ReflectHelper.UnwrapTargetInvocationException(e);
}
}

Expand Down
11 changes: 1 addition & 10 deletions src/NHibernate/Intercept/DefaultDynamicLazyFieldInterceptor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,7 @@ public object Intercept(InvocationInfo info)
}
}

object returnValue;
try
{
returnValue = info.InvokeMethodOnTarget();
}
catch (TargetInvocationException ex)
{
throw ReflectHelper.UnwrapTargetInvocationException(ex);
}
return returnValue;
return info.InvokeMethodOnTarget();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unwrapping moved into InvokeMethodOnTarget, which is called two times in NHibernate code: here and a couple of lines above here.

}
}
}
2 changes: 1 addition & 1 deletion src/NHibernate/Linq/DefaultQueryProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected virtual object ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery
}
catch (TargetInvocationException e)
{
throw e.InnerException;
throw ReflectHelper.UnwrapTargetInvocationException(e);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/NHibernate/Persister/PersisterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using NHibernate.Mapping;
using NHibernate.Persister.Collection;
using NHibernate.Persister.Entity;
using NHibernate.Util;

namespace NHibernate.Persister
{
Expand Down Expand Up @@ -101,7 +102,7 @@ public static IEntityPersister Create(System.Type persisterClass, PersistentClas
Exception e = tie.InnerException;
if (e is HibernateException)
{
throw e;
throw ReflectHelper.UnwrapTargetInvocationException(tie);
}
else
{
Expand Down Expand Up @@ -143,7 +144,7 @@ public static ICollectionPersister Create(System.Type persisterClass, Mapping.Co
Exception e = tie.InnerException;
if (e is HibernateException)
{
throw e;
throw ReflectHelper.UnwrapTargetInvocationException(tie);
}
else
{
Expand Down
15 changes: 12 additions & 3 deletions src/NHibernate/Proxy/DynamicProxy/InvocationInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

#endregion

using System;
using System.Diagnostics;
using System.Reflection;
using System.Text;
using NHibernate.Util;

namespace NHibernate.Proxy.DynamicProxy
{
Expand Down Expand Up @@ -105,7 +105,16 @@ private string GetMethodName(MethodInfo method)

public virtual object InvokeMethodOnTarget()
{
return _callbackMethod.Invoke(Target, Arguments);
object returnValue;
try
{
returnValue = _callbackMethod.Invoke(Target, Arguments);
}
catch (TargetInvocationException ex)
{
throw ReflectHelper.UnwrapTargetInvocationException(ex);
}
return returnValue;
}
}
}
}