-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Limitation in the inheritance hierarchy using dynamic proxy?
PostPosted: Thu Nov 15, 2007 7:47 am 
Newbie

Joined: Thu Nov 15, 2007 7:31 am
Posts: 4
Location: Denmark, CET
I get an exception stating that the fullname of the dynamic proxy is too long when I use dynamic proxies in an inheritance hierarchy. I have followed the guidelines in the documentation to use interfaces as dynamic proxies so that I can handle the polymorphy in the inheritance hierarchy.

It have worked fine for a very long time, but suddenly I get an error as specified below. It happended after I increased the size of the inheritance hieraarchy (added another joined-subclass with a dynamic proxy)

I remember that I previously noted that the name of the dynamic proxy seems to be constructed from all the interfaces the inheritance hierarchy covers. If that is the convention, then I guess I have run in to a limitation in the size of the inheritance hierarchy as the fully quilified name of a Type in C# seems to be 1024.

Are there any suggestions to how to avoid this problem? Or is this a feature/bug in NHibernate that should be fixed?

I look forward to hear responses.

- Klaus


NHibernate 1.2.0:

Full stack trace of any exception that occurs:

2007-11-15 12:12:00,161 [4] ERROR NHibernate.Proxy.CastleProxyFactory [(null)] - Creating a proxy instance failed
System.ArgumentException: Type name was too long. The fully qualified type name must be less than 1,024 characters.
Parameter name: fullname
at System.Reflection.Emit.TypeBuilder.Init(String fullname, TypeAttributes attr, Type parent, Type[] interfaces, Module module, PackingSize iPackingSize, Int32 iTypeSize, TypeBuilder enclosingType)
at System.Reflection.Emit.ModuleBuilder.DefineTypeNoLock(String name, TypeAttributes attr, Type parent, Type[] interfaces)
at System.Reflection.Emit.ModuleBuilder.DefineType(String name, TypeAttributes attr, Type parent, Type[] interfaces)
at Castle.DynamicProxy.Builder.CodeBuilder.EasyType..ctor(ModuleScope modulescope, String name, Type baseType, Type[] interfaces, Boolean serializable)
at Castle.DynamicProxy.Builder.CodeGenerators.BaseCodeGenerator.CreateTypeBuilder(String typeName, Type baseType, Type[] interfaces)
at Castle.DynamicProxy.Builder.CodeGenerators.InterfaceProxyGenerator.GenerateCode(Type[] interfaces, Type targetType)
at Castle.DynamicProxy.Builder.DefaultProxyBuilder.CreateInterfaceProxy(Type[] interfaces, Type type)
at Castle.DynamicProxy.ProxyGenerator.CreateProxy(Type[] interfaces, IInterceptor interceptor, Object target)
at NHibernate.Proxy.CastleProxyFactory.GetProxy(Object id, ISessionImplementor session)
2007-11-15 12:12:47,443 [4] WARN ASP.global_asax [(null)] -
System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> NHibernate.HibernateException: Creating a proxy instance failed ---> System.ArgumentException: Type name was too long. The fully qualified type name must be less than 1,024 characters.
Parameter name: fullname
at System.Reflection.Emit.TypeBuilder.Init(String fullname, TypeAttributes attr, Type parent, Type[] interfaces, Module module, PackingSize iPackingSize, Int32 iTypeSize, TypeBuilder enclosingType)
at System.Reflection.Emit.ModuleBuilder.DefineTypeNoLock(String name, TypeAttributes attr, Type parent, Type[] interfaces)
at System.Reflection.Emit.ModuleBuilder.DefineType(String name, TypeAttributes attr, Type parent, Type[] interfaces)
at Castle.DynamicProxy.Builder.CodeBuilder.EasyType..ctor(ModuleScope modulescope, String name, Type baseType, Type[] interfaces, Boolean serializable)
at Castle.DynamicProxy.Builder.CodeGenerators.BaseCodeGenerator.CreateTypeBuilder(String typeName, Type baseType, Type[] interfaces)
at Castle.DynamicProxy.Builder.CodeGenerators.InterfaceProxyGenerator.GenerateCode(Type[] interfaces, Type targetType)
at Castle.DynamicProxy.Builder.DefaultProxyBuilder.CreateInterfaceProxy(Type[] interfaces, Type type)
at Castle.DynamicProxy.ProxyGenerator.CreateProxy(Type[] interfaces, IInterceptor interceptor, Object target)
at NHibernate.Proxy.CastleProxyFactory.GetProxy(Object id, ISessionImplementor session)
--- End of inner exception stack trace ---
at NHibernate.Proxy.CastleProxyFactory.GetProxy(Object id, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.CreateProxy(Object id, ISessionImplementor session)
at NHibernate.Impl.SessionImpl.DoLoadByClass(Type clazz, Object id, Boolean checkDeleted, Boolean allowProxyCreation)
at NHibernate.Impl.SessionImpl.Load(Type clazz, Object id)
at Mimer.Data.DAO.BaseDAO.GetEntityByOID[T,I](String oid) in E:\DotnetWorkarea\Mimer\Mimer\Mimer.Data\DAO\BaseDAO.cs:line 29
at Mimer.Business.Managers.InterfaceBaseManager`2.GetEntityByOID(String oid) in E:\DotnetWorkarea\Mimer\Mimer\Mimer.Business\Managers\InterfaceBaseManager.cs:line 76
at Mimer.Web.Common.AbstractEquipmentDetail.LoadDomainObject(String eqpOid) in e:\DotnetWorkarea\Mimer\Mimer\Mimer.Web\App_Code\Common\AbstractEquipmentDetail.cs:line 261
at Mimer.Web.Common.AbstractEquipmentDetail.Page_Load(Object sender, EventArgs e) in e:\DotnetWorkarea\Mimer\Mimer\Mimer.Web\App_Code\Common\AbstractEquipmentDetail.cs:line 200
at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
at System.Web.UI.Control.OnLoad(EventArgs e)
at Mimer.Web.Common.AbstractDetailPageControl.OnLoad(EventArgs e) in e:\DotnetWorkarea\Mimer\Mimer\Mimer.Web\App_Code\Common\AbstractDetailPageControl.cs:line 25
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
--- End of inner exception stack trace ---
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.pages_equipments_equipmentdetail_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\mimer.web\e028db3e\b5af1485\App_Web_b4v00e-k.20.cs:line 0
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


Oracle 9i:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 15, 2007 10:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
That's a limitation of the Castle proxy library. NHibernate does not specify the class name of the generated proxy. I would suggest searching the Castle forum and see if you can find anything there.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 15, 2007 2:52 pm 
Newbie

Joined: Thu Nov 15, 2007 7:31 am
Posts: 4
Location: Denmark, CET
Thanks, but that was not what i hoped to be the answer. I have though downloaded the source code for NHibernate and Castle Dynamic Proxy and then I will try to figure out a solution.

I will also look into the Castle forums to see if they have a workarround for the problem.

The problem is that this is a showstopper for our project.

I will post the result of what I find.

Thanks anyway.


Top
 Profile  
 
 Post subject: A solution is change a few lines of code in DynamicProxy
PostPosted: Fri Nov 16, 2007 9:02 am 
Newbie

Joined: Thu Nov 15, 2007 7:31 am
Posts: 4
Location: Denmark, CET
Hi

I have made a solution/workarround now.

I changed a few lines of code in the DynamicProxy source code. The changes are made in InterfaceProxyGenerator:

Code:
protected override String GenerateTypeName(Type type, Type[] interfaces)
{
   StringBuilder sb = new StringBuilder();
   foreach(Type inter in interfaces)
   {
      sb.Append('_');
      sb.Append(GetTypeName(inter));
   }
   string aName = String.Format("ProxyInterface{2}{0}{1}", GetTypeName(type), sb.ToString(), NormalizeNamespaceName(type.Namespace));
   // KBW: If the generated type is larger than 1024 (a limitation in the CLR)
   // then use the hascode of the generated name of the interfaces. That way we
   // ensure that the type name will never exceed 1024.
   if (aName.Length > 1024) {
      aName = String.Format("ProxyInterface{2}{0}{1}", GetTypeName(type), sb.ToString().GetHashCode(), NormalizeNamespaceName(type.Namespace));
   }
   return aName;
}



After rebuilding the Castle.DynamicProxy.dll and using that I do not run into the problem anymore. I am not aware of whether my workarround can cause unexpected errors so I have posted a reply on the Castle forum as well: http://forum.castleproject.org/viewtopic.php?t=3783.

I do hope that the castle guys will implement a solution in their baseline.

I hope this can help someone.

- Klaus


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 16, 2007 9:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
Thanks for sharing your findings and solution.

_________________
Karl Chu


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.