Skip to content

Proxy creation fail for class with explicit generic interface #3034

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 4 commits into from
Mar 20, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ protected override HbmMapping GetMappings()
rc.Property(x => x.Name);
});

mapper.Class<EntityWithExplicitGenericInterface>(
rc =>
{
rc.Table("explGenInterface");
rc.Id(x => x.Id);
});

return mapper.CompileMappingForAllExplicitlyAddedEntities();
}

Expand Down Expand Up @@ -177,6 +184,15 @@ public async Task ProxyInterfaceIdAccessFromDifferentInterfacesAsync()
}
}

[Test]
public void ProxyExplicitGenericInterfaceAsync()
{
using (var session = OpenSession())
{
Assert.That(() => session.LoadAsync<EntityWithExplicitGenericInterface>(_id), Throws.Nothing, "Failed to load EntityWithExplicitGenericInterface proxy");
}
}

private void ThrowOnIEntityNameAccess(IEntity entity)
{
Assert.That(() => entity.Name, Throws.TypeOf<ObjectNotFoundException>(), "IEntity.Name access should lead to proxy initialization");
Expand Down
15 changes: 15 additions & 0 deletions src/NHibernate.Test/StaticProxyTest/InterfaceHandling/Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,19 @@ public class EntityWithSuperClassInterfaceLookup

public virtual IEntity EntityLookup { get; set; }
}

public class EntityWithExplicitGenericInterface : IGeneric
{
public virtual Guid Id { get; set; }

T[] IGeneric.GetTypes<T>()
{
return null;
}
}

public interface IGeneric
{
T[] GetTypes<T>();
}
}
16 changes: 16 additions & 0 deletions src/NHibernate.Test/StaticProxyTest/InterfaceHandling/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ protected override HbmMapping GetMappings()
rc.Property(x => x.Name);
});

mapper.Class<EntityWithExplicitGenericInterface>(
rc =>
{
rc.Table("explGenInterface");
rc.Id(x => x.Id);
});

return mapper.CompileMappingForAllExplicitlyAddedEntities();
}

Expand Down Expand Up @@ -166,6 +173,15 @@ public void ProxyInterfaceIdAccessFromDifferentInterfaces()
}
}

[Test]
public void ProxyExplicitGenericInterface()
{
using (var session = OpenSession())
{
Assert.That(() => session.Load<EntityWithExplicitGenericInterface>(_id), Throws.Nothing, "Failed to load EntityWithExplicitGenericInterface proxy");
}
}

private void ThrowOnIEntityNameAccess(IEntity entity)
{
Assert.That(() => entity.Name, Throws.TypeOf<ObjectNotFoundException>(), "IEntity.Name access should lead to proxy initialization");
Expand Down
5 changes: 3 additions & 2 deletions src/NHibernate/Proxy/ProxyBuilderHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,6 @@ internal static MethodBuilder GenerateMethodSignature(string name, MethodInfo me
CallingConventions.HasThis,
method.ReturnType,
parameters.ToArray(param => param.ParameterType));
if (explicitImplementation)
methodBuilder.SetImplementationFlags(MethodImplAttributes.Managed | MethodImplAttributes.IL);

var typeArgs = method.GetGenericArguments();
if (typeArgs.Length > 0)
Expand Down Expand Up @@ -208,6 +206,9 @@ internal static MethodBuilder GenerateMethodSignature(string name, MethodInfo me
}
}

if (explicitImplementation)
methodBuilder.SetImplementationFlags(MethodImplAttributes.Managed | MethodImplAttributes.IL);

return methodBuilder;
}

Expand Down