Skip to content

Commit

Permalink
Merge branch 'NH-3500-PR487'
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarb committed Jul 31, 2016
2 parents a6c78c3 + e4ffde7 commit d1c7e3f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
8 changes: 8 additions & 0 deletions releasenotes.txt
@@ -1,3 +1,11 @@
Tentative for 4.1:

Possible breaking change: Proxies for classes that used lazy fields (not collections)
would have any exceptions from the entity wrapped in TargetInvocationException. This
wrapping exception have now been removed. Where relevant, you should instead catch
the original exception type you throw.


Build 4.0.4.GA
=============================

Expand Down
Expand Up @@ -6,12 +6,18 @@

namespace NHibernate.Test.DynamicProxyTests
{
public class LazyFieldInterceptorSerializable
public class LazyFieldInterceptorTests
{
[Serializable]
public class MyClass
{
public virtual int Id { get; set; }

public virtual void ThrowError()
{
// Use some specific exception type to avoid using the base class.
throw new FormatException("test");
}
}

[Test]
Expand All @@ -31,5 +37,16 @@ public void LazyFieldInterceptorIsBinarySerializable()

Assert.That(fieldInterceptionProxy, Is.BinarySerializable);
}


[Test]
public void DefaultDynamicLazyFieldInterceptorUnWrapsTIEExceptions()
{
var pf = new DefaultProxyFactory();
var propertyInfo = typeof(MyClass).GetProperty("Id");
pf.PostInstantiate("MyClass", typeof(MyClass), new HashSet<System.Type>(), propertyInfo.GetGetMethod(), propertyInfo.GetSetMethod(), null);
var myClassProxied = (MyClass)pf.GetFieldInterceptionProxy(new MyClass());
Assert.Throws<FormatException>(() => myClassProxied.ThrowError(), "test");
}
}
}
}
3 changes: 1 addition & 2 deletions src/NHibernate.Test/NHibernate.Test.csproj
Expand Up @@ -258,7 +258,7 @@
<Compile Include="DynamicProxyTests\InterfaceProxySerializationTests\MyProxyImpl.cs" />
<Compile Include="DynamicProxyTests\InterfaceProxySerializationTests\ProxyFixture.cs" />
<Compile Include="DynamicProxyTests\InterfaceWithEqualsGethashcodeTests.cs" />
<Compile Include="DynamicProxyTests\LazyFieldInterceptorSerializable.cs" />
<Compile Include="DynamicProxyTests\LazyFieldInterceptorTests.cs" />
<Compile Include="DynamicProxyTests\PassThroughInterceptor.cs" />
<Compile Include="DynamicProxyTests\PeVerifier.cs" />
<Compile Include="DynamicProxyTests\ProxiedMembers\Fixture.cs" />
Expand Down Expand Up @@ -3754,7 +3754,6 @@
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup>

</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
14 changes: 12 additions & 2 deletions src/NHibernate/Intercept/DefaultDynamicLazyFieldInterceptor.cs
@@ -1,4 +1,5 @@
using System;
using System.Reflection;
using NHibernate.Proxy.DynamicProxy;
using NHibernate.Util;

Expand Down Expand Up @@ -50,7 +51,16 @@ public object Intercept(InvocationInfo info)
}
}

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

0 comments on commit d1c7e3f

Please sign in to comment.