Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

C# 8/11 Static interface members support #3295

Closed
NikitaEgorov opened this issue Apr 28, 2023 · 4 comments 路 Fixed by #3298
Closed

C# 8/11 Static interface members support #3295

NikitaEgorov opened this issue Apr 28, 2023 · 4 comments 路 Fixed by #3298

Comments

@NikitaEgorov
Copy link

When I tried to use C# 11 general math I got an exception 馃槩

NHibernate.HibernateException: Creating a proxy instance failed
 ---> System.TypeLoadException: Signature of the body and declaration in a method implementation do not match.  Type: 'ChatProxy'.  Assembly: 'ChatProxyAssembly,
 Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()
   at System.Reflection.Emit.TypeBuilder.CreateTypeInfoImpl()
   at System.Reflection.Emit.TypeBuilder.CreateTypeInfo()
   at NHibernate.Proxy.NHibernateProxyBuilder.CreateProxyType(Type baseType, IReadOnlyCollection`1 baseInterfaces)
   at NHibernate.Proxy.StaticProxyFactory.CreateProxyActivator(ProxyCacheEntry pke)
   at NHibernate.Proxy.StaticProxyFactory.<GetProxy>b__5_0(ProxyCacheEntry pke)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at NHibernate.Proxy.StaticProxyFactory.GetProxy(Object id, ISessionImplementor session)
   --- End of inner exception stack trace ---
   at NHibernate.Proxy.StaticProxyFactory.GetProxy(Object id, ISessionImplementor session)
   at NHibernate.Tuple.Entity.AbstractEntityTuplizer.CreateProxy(Object id, ISessionImplementor session)
   at NHibernate.Persister.Entity.AbstractEntityPersister.CreateProxy(Object id, ISessionImplementor session)
   at NHibernate.Event.Default.DefaultLoadEventListener.CreateProxyIfNecessary(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options, IPersistenceContext persistenceContext)
   at NHibernate.Event.Default.DefaultLoadEventListener.ProxyOrLoadAsync(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options, CancellationToken cancellationToken)
--- End of stack trace from previous location ---
   at NHibernate.Event.Default.DefaultLoadEventListener.OnLoadAsync(LoadEvent event, LoadType loadType, CancellationToken cancellationToken)
   at NHibernate.Impl.SessionImpl.FireLoadAsync(LoadEvent event, LoadType loadType, CancellationToken cancellationToken)
   at NHibernate.Impl.SessionImpl.InternalLoadAsync(String entityName, Object id, Boolean eager, Boolean isNullable, CancellationToken cancellationToken)
   at NHibernate.Type.EntityType.ResolveIdentifierAsync(Object id, ISessionImplementor session, CancellationToken cancellationToken)
   at NHibernate.Engine.TwoPhaseLoad.InitializeEntityAsync(Object entity, Boolean readOnly, ISessionImplementor session, PreLoadEvent preLoadEvent, PostLoadEvent postLoadEvent, Action`2 cacheBatchingHandler, CancellationTok
en cancellationToken)
   at NHibernate.Loader.Loader.InitializeEntitiesAndCollectionsAsync(IList hydratedObjects, DbDataReader reader, ISessionImplementor session, Boolean readOnly, CacheBatcher cacheBatcher, CancellationToken cancellationToken)
   at NHibernate.Loader.Loader.DoQueryAsync(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies, IResultTransformer forcedResultTransformer, QueryCacheResultBuilder queryCacheResultBuilder, C
ancellationToken cancellationToken)
   at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollectionsAsync(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies, IResultTransformer forcedResultTransformer, QueryCacheResultBui
lder queryCacheResultBuilder, CancellationToken cancellationToken)
   at NHibernate.Loader.Loader.DoListAsync(ISessionImplementor session, QueryParameters queryParameters, IResultTransformer forcedResultTransformer, QueryCacheResultBuilder queryCacheResultBuilder, CancellationToken cancell
ationToken)
   at NHibernate.Loader.Loader.ListIgnoreQueryCacheAsync(ISessionImplementor session, QueryParameters queryParameters, CancellationToken cancellationToken)
   at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.ListAsync(ISessionImplementor session, QueryParameters queryParameters, CancellationToken cancellationToken)
   at NHibernate.Engine.Query.HQLQueryPlan.PerformListAsync(QueryParameters queryParameters, ISessionImplementor session, IList results, CancellationToken cancellationToken)
   at NHibernate.Impl.SessionImpl.ListAsync(IQueryExpression queryExpression, QueryParameters queryParameters, IList results, Object filterConnection, CancellationToken cancellationToken)
   at NHibernate.Impl.SessionImpl.ListAsync(IQueryExpression queryExpression, QueryParameters queryParameters, IList results, Object filterConnection, CancellationToken cancellationToken)
   at NHibernate.Impl.AbstractSessionImpl.ListAsync[T](IQueryExpression query, QueryParameters parameters, CancellationToken cancellationToken)
   at NHibernate.Impl.AbstractQueryImpl2.ListAsync[T](CancellationToken cancellationToken)
   at NHibernate.Linq.DefaultQueryProvider.ExecuteListAsync[TResult](Expression expression, CancellationToken cancellationToken)
   at NHibernate.Linq.LinqExtensionMethods.<>c__DisplayClass59_0`1.<<ToListAsync>g__InternalToListAsync|0>d.MoveNext()
--- End of stack trace from previous location ---
@hazzik
Copy link
Member

hazzik commented May 1, 2023

Hi @NikitaEgorov can you please give us some examples? Is your class to be proxied has generic operator? Or what?

@NikitaEgorov
Copy link
Author

@hazzik
I can't reproduce this issue in NHibernate source code because it uses NET6.0
I reproduce in my own project

Luxoft/BSSFramework@main...negorov/nhib-3295

Steps:

Create Interface

public interface ICreator
{
    static abstract void Create();
}

Implement Interface in "reference class"

public partial class BusinessUnitType :  ICreator
{
    public static void Create()
    {
        // Actively doing nothin
    }
}

Mapping

 <class name="SampleSystem.Domain.BusinessUnit" table="BusinessUnit">
    <id name="Id" column="id" type="Guid" access="field.camelcase">
      <generator class="guid.comb" />
    </id>
    <version name="Version" generated="never" type="Int64">
      <column name="Version" not-null="false" sql-type="bigint" />
    </version>
    <many-to-one name="BusinessUnitType" column="businessUnitTypeId" class="SampleSystem.Domain.BusinessUnitType" access="field.camelcase" />
  </class>

 <class name="SampleSystem.Domain.BusinessUnitType" table="BusinessUnitType">
    <id name="Id" column="id" type="Guid" access="field.camelcase">
      <generator class="guid.comb" />
    </id>
    <version name="Version" generated="never" type="Int64">
      <column name="Version" not-null="false" sql-type="bigint" />
    </version>
    <property name="Name" column="name" unique-key="UIX_nameBusinessUnitType" access="field.camelcase" />
  </class>

Load "parent" class from database without fetch

 var list = businessUnitRepository.GetQueryable().ToList();

@hazzik
Copy link
Member

hazzik commented May 2, 2023

Thank you.

I can't reproduce this issue in NHibernate source code because it uses NET6.0

Feel free to change it to .NET 7.

interface
static abstract

This is what I suspected.

@hazzik hazzik changed the title C# 11 Generic Math Exception C# 11 Static interface members exception May 2, 2023
@hazzik hazzik changed the title C# 11 Static interface members exception C# 8/11 Static interface members exception May 2, 2023
@hazzik
Copy link
Member

hazzik commented May 2, 2023

Same happens with C# 8 static interface members

@fredericDelaporte fredericDelaporte added this to the 5.4.3 milestone May 8, 2023
@fredericDelaporte fredericDelaporte changed the title C# 8/11 Static interface members exception C# 8/11 Static interface members support May 8, 2023
hazzik added a commit that referenced this issue May 8, 2023
@hazzik hazzik closed this as completed May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants