Skip to content

Commit 2344bd8

Browse files
Fix Proxy creation failure for explicit generic interface (#3034)
Fix #3029
1 parent 211891f commit 2344bd8

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

src/NHibernate.Test/Async/StaticProxyTest/InterfaceHandling/Fixture.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ protected override HbmMapping GetMappings()
9898
rc.Property(x => x.Name);
9999
});
100100

101+
mapper.Class<EntityWithExplicitGenericInterface>(
102+
rc =>
103+
{
104+
rc.Table("explGenInterface");
105+
rc.Id(x => x.Id);
106+
});
107+
101108
return mapper.CompileMappingForAllExplicitlyAddedEntities();
102109
}
103110

@@ -177,6 +184,15 @@ public async Task ProxyInterfaceIdAccessFromDifferentInterfacesAsync()
177184
}
178185
}
179186

187+
[Test]
188+
public void ProxyExplicitGenericInterfaceAsync()
189+
{
190+
using (var session = OpenSession())
191+
{
192+
Assert.That(() => session.LoadAsync<EntityWithExplicitGenericInterface>(_id), Throws.Nothing, "Failed to load EntityWithExplicitGenericInterface proxy");
193+
}
194+
}
195+
180196
private void ThrowOnIEntityNameAccess(IEntity entity)
181197
{
182198
Assert.That(() => entity.Name, Throws.TypeOf<ObjectNotFoundException>(), "IEntity.Name access should lead to proxy initialization");

src/NHibernate.Test/StaticProxyTest/InterfaceHandling/Entities.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,19 @@ public class EntityWithSuperClassInterfaceLookup
7979

8080
public virtual IEntity EntityLookup { get; set; }
8181
}
82+
83+
public class EntityWithExplicitGenericInterface : IGeneric
84+
{
85+
public virtual Guid Id { get; set; }
86+
87+
T[] IGeneric.GetTypes<T>()
88+
{
89+
return null;
90+
}
91+
}
92+
93+
public interface IGeneric
94+
{
95+
T[] GetTypes<T>();
96+
}
8297
}

src/NHibernate.Test/StaticProxyTest/InterfaceHandling/Fixture.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ protected override HbmMapping GetMappings()
8787
rc.Property(x => x.Name);
8888
});
8989

90+
mapper.Class<EntityWithExplicitGenericInterface>(
91+
rc =>
92+
{
93+
rc.Table("explGenInterface");
94+
rc.Id(x => x.Id);
95+
});
96+
9097
return mapper.CompileMappingForAllExplicitlyAddedEntities();
9198
}
9299

@@ -166,6 +173,15 @@ public void ProxyInterfaceIdAccessFromDifferentInterfaces()
166173
}
167174
}
168175

176+
[Test]
177+
public void ProxyExplicitGenericInterface()
178+
{
179+
using (var session = OpenSession())
180+
{
181+
Assert.That(() => session.Load<EntityWithExplicitGenericInterface>(_id), Throws.Nothing, "Failed to load EntityWithExplicitGenericInterface proxy");
182+
}
183+
}
184+
169185
private void ThrowOnIEntityNameAccess(IEntity entity)
170186
{
171187
Assert.That(() => entity.Name, Throws.TypeOf<ObjectNotFoundException>(), "IEntity.Name access should lead to proxy initialization");

src/NHibernate/Proxy/ProxyBuilderHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,6 @@ internal static MethodBuilder GenerateMethodSignature(string name, MethodInfo me
178178
CallingConventions.HasThis,
179179
method.ReturnType,
180180
parameters.ToArray(param => param.ParameterType));
181-
if (explicitImplementation)
182-
methodBuilder.SetImplementationFlags(MethodImplAttributes.Managed | MethodImplAttributes.IL);
183181

184182
var typeArgs = method.GetGenericArguments();
185183
if (typeArgs.Length > 0)
@@ -208,6 +206,9 @@ internal static MethodBuilder GenerateMethodSignature(string name, MethodInfo me
208206
}
209207
}
210208

209+
if (explicitImplementation)
210+
methodBuilder.SetImplementationFlags(MethodImplAttributes.Managed | MethodImplAttributes.IL);
211+
211212
return methodBuilder;
212213
}
213214

0 commit comments

Comments
 (0)