Skip to content

Commit d1c7e3f

Browse files
committed
Merge branch 'NH-3500-PR487'
2 parents a6c78c3 + e4ffde7 commit d1c7e3f

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

releasenotes.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Tentative for 4.1:
2+
3+
Possible breaking change: Proxies for classes that used lazy fields (not collections)
4+
would have any exceptions from the entity wrapped in TargetInvocationException. This
5+
wrapping exception have now been removed. Where relevant, you should instead catch
6+
the original exception type you throw.
7+
8+
19
Build 4.0.4.GA
210
=============================
311

src/NHibernate.Test/DynamicProxyTests/LazyFieldInterceptorSerializable.cs renamed to src/NHibernate.Test/DynamicProxyTests/LazyFieldInterceptorTests.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66

77
namespace NHibernate.Test.DynamicProxyTests
88
{
9-
public class LazyFieldInterceptorSerializable
9+
public class LazyFieldInterceptorTests
1010
{
1111
[Serializable]
1212
public class MyClass
1313
{
1414
public virtual int Id { get; set; }
15+
16+
public virtual void ThrowError()
17+
{
18+
// Use some specific exception type to avoid using the base class.
19+
throw new FormatException("test");
20+
}
1521
}
1622

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

3238
Assert.That(fieldInterceptionProxy, Is.BinarySerializable);
3339
}
40+
41+
42+
[Test]
43+
public void DefaultDynamicLazyFieldInterceptorUnWrapsTIEExceptions()
44+
{
45+
var pf = new DefaultProxyFactory();
46+
var propertyInfo = typeof(MyClass).GetProperty("Id");
47+
pf.PostInstantiate("MyClass", typeof(MyClass), new HashSet<System.Type>(), propertyInfo.GetGetMethod(), propertyInfo.GetSetMethod(), null);
48+
var myClassProxied = (MyClass)pf.GetFieldInterceptionProxy(new MyClass());
49+
Assert.Throws<FormatException>(() => myClassProxied.ThrowError(), "test");
50+
}
3451
}
35-
}
52+
}

src/NHibernate.Test/NHibernate.Test.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
<Compile Include="DynamicProxyTests\InterfaceProxySerializationTests\MyProxyImpl.cs" />
259259
<Compile Include="DynamicProxyTests\InterfaceProxySerializationTests\ProxyFixture.cs" />
260260
<Compile Include="DynamicProxyTests\InterfaceWithEqualsGethashcodeTests.cs" />
261-
<Compile Include="DynamicProxyTests\LazyFieldInterceptorSerializable.cs" />
261+
<Compile Include="DynamicProxyTests\LazyFieldInterceptorTests.cs" />
262262
<Compile Include="DynamicProxyTests\PassThroughInterceptor.cs" />
263263
<Compile Include="DynamicProxyTests\PeVerifier.cs" />
264264
<Compile Include="DynamicProxyTests\ProxiedMembers\Fixture.cs" />
@@ -3754,7 +3754,6 @@
37543754
<Folder Include="Properties\" />
37553755
</ItemGroup>
37563756
<ItemGroup>
3757-
37583757
</ItemGroup>
37593758
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
37603759
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

src/NHibernate/Intercept/DefaultDynamicLazyFieldInterceptor.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Reflection;
23
using NHibernate.Proxy.DynamicProxy;
34
using NHibernate.Util;
45

@@ -50,7 +51,16 @@ public object Intercept(InvocationInfo info)
5051
}
5152
}
5253

53-
return info.InvokeMethodOnTarget();
54+
object returnValue;
55+
try
56+
{
57+
returnValue = info.InvokeMethodOnTarget();
58+
}
59+
catch (TargetInvocationException ex)
60+
{
61+
throw ReflectHelper.UnwrapTargetInvocationException(ex);
62+
}
63+
return returnValue;
5464
}
5565
}
56-
}
66+
}

0 commit comments

Comments
 (0)