Skip to content

Commit 6e8f190

Browse files
committed
Fix TypeLoadException in StaticProxyFactory when class has not visible interfaces
Fixes #1643
1 parent 6e17b76 commit 6e8f190

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using System.Collections.Generic;
2+
using NHibernate.Proxy;
3+
using NUnit.Framework;
4+
5+
namespace NHibernate.Test.StaticProxyTest
6+
{
7+
public class StaticProxyFactoryFixture
8+
{
9+
internal interface ISomething
10+
{
11+
int Id { get; }
12+
}
13+
14+
public class TestClass : ISomething
15+
{
16+
public virtual int Id { get; set; }
17+
}
18+
19+
[Test]
20+
public void CanCreateProxyForClassWithInternalInterface()
21+
{
22+
var factory = new StaticProxyFactory();
23+
factory.PostInstantiate(typeof(TestClass).FullName, typeof(TestClass), new HashSet<System.Type> {typeof(INHibernateProxy)}, null, null, null);
24+
var proxy = factory.GetProxy(1, null);
25+
Assert.That(proxy, Is.Not.Null);
26+
}
27+
}
28+
}

src/NHibernate/Proxy/NHibernateProxyBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public TypeInfo CreateProxyType(System.Type baseType, IReadOnlyCollection<System
7474
interfaces.Add(baseType);
7575
}
7676

77+
interfaces.RemoveWhere(i => !i.IsVisible);
78+
7779
var typeBuilder = moduleBuilder.DefineType(typeName, typeAttributes, parentType, interfaces.ToArray());
7880

7981
var lazyInitializerField = typeBuilder.DefineField("__lazyInitializer", LazyInitializerType, FieldAttributes.Private);

0 commit comments

Comments
 (0)