gpt4 book ai didi

.NET 4.0 解决方案中的 NHibernate 1.2

转载 作者:行者123 更新时间:2023-12-03 06:55:22 25 4
gpt4 key购买 nike

我有一些基于 NHibernate 1.2 的项目,我想将它们添加到 .NET 4.0 解决方案中,但我收到 AmbigouslyMatchException。
无论这些项目是针对2.0还是4.0框架。
如果我将它们添加到 .NET 3.5 解决方案中,它就可以工作。

有人有这方面的经验吗?

这是一个异常(exception):

[AmbiguousMatchException: Ambiguous match found.]
System.RuntimeType.GetMethodImpl(String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers) +9607924
System.Type.GetMethod(String name) +29
Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST.LockBlockExpression.Emit(IEasyMember member, ILGenerator gen) +192
Castle.DynamicProxy.Builder.CodeBuilder.SimpleAST.ExpressionStatement.Emit(IEasyMember member, ILGenerator gen) +52
Castle.DynamicProxy.Builder.CodeBuilder.AbstractCodeBuilder.Generate(IEasyMember member, ILGenerator il) +370
Castle.DynamicProxy.Builder.CodeBuilder.EasyMethod.Generate() +71
Castle.DynamicProxy.Builder.CodeBuilder.AbstractEasyType.EnsureBuildersAreInAValidState() +706
Castle.DynamicProxy.Builder.CodeBuilder.AbstractEasyType.BuildType() +90
Castle.DynamicProxy.Builder.CodeGenerators.BaseCodeGenerator.CreateType() +55
Castle.DynamicProxy.Builder.CodeGenerators.ClassProxyGenerator.GenerateCode(Type baseClass, Type[] interfaces) +573
Castle.DynamicProxy.Builder.DefaultProxyBuilder.CreateClassProxy(Type theClass, Type[] interfaces) +87
Castle.DynamicProxy.ProxyGenerator.CreateClassProxy(Type baseClass, Type[] interfaces, IInterceptor interceptor, Boolean checkAbstract, Object[] argumentsForConstructor) +116
NHibernate.Proxy.CastleProxyFactory.GetProxy(Object id, ISessionImplementor session) +136

[HibernateException: Creating a proxy instance failed]
NHibernate.Proxy.CastleProxyFactory.GetProxy(Object id, ISessionImplementor session) +270
NHibernate.Persister.Entity.AbstractEntityPersister.CreateProxy(Object id, ISessionImplementor session) +17
NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation) +354
NHibernate.Impl.SessionImpl.InternalLoad(Type clazz, Object id, Boolean eager, Boolean isNullable) +52
NHibernate.Type.EntityType.ResolveIdentifier(Object id, ISessionImplementor session) +37
NHibernate.Type.EntityType.ResolveIdentifier(Object id, ISessionImplementor session, Object owner) +55
NHibernate.Impl.SessionImpl.InitializeEntity(Object obj) +187
NHibernate.Loader.Loader.InitializeEntitiesAndCollections(IList hydratedObjects, Object resultSetId, ISessionImplementor session) +229
NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +702
NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +62
NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +51
NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) +18
NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes) +81
NHibernate.Loader.Criteria.CriteriaLoader.List(ISessionImplementor session) +36
NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria, IList results) +315
NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria) +66
NHibernate.Impl.CriteriaImpl.List() +54
[my code calling Criteria.List()]

最佳答案

根据 Rup 的评论,我解决了更改 CaSTLe DynamicProxy 1.1.5 的源并重新编译的问题。
问题是通过反射调用 System.Threading.Monitor.Enter 方法而不指定参数(这是因为在 .NET 2.0 中只有 1 个签名),但从 .NET 4.0 开始,该方法有 2 个重载。

我修改了类 CaSTLe.DynamicProxy.Builder.CodeBuilder.SimpleAST.LockBlockExpression,更改了行

gen.Emit(OpCodes.Call, typeof(Monitor).GetMethod("Enter"));

与行

gen.Emit(OpCodes.Call, typeof(Monitor).GetMethod("Enter", new Type[] { typeof(object) }));

我有 NHibernate 1.2 的源码 from SourceForge同时我用Reflector反汇编了CaSTLe DynamicProxy 1.1.5的代码。

关于.NET 4.0 解决方案中的 NHibernate 1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3301157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com