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.  [ 3 posts ] 
Author Message
 Post subject: Deserialize ex in ProxyObjectReference.RecreateClassProxy()
PostPosted: Mon Nov 26, 2007 5:58 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
Hibernate version: 1.2.0.GA

I'm trying to create a visualizers for my entity classes, for use in the Microsoft Visual Studio debugger. When it tries to deserialize the entity, I get exceptions like this:


Code:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Object of type 'System.Boolean' cannot be converted to type 'System.String'.
   at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
   at System.Reflection.RtFieldInfo.InternalSetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, Boolean doVisibilityCheck, Boolean doCheckConsistency)
   at System.Runtime.Serialization.SerializationFieldInfo.InternalSetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture, Boolean requiresAccessCheck, Boolean isBinderDefault)
   at System.Runtime.Serialization.FormatterServices.SerializationSetValue(MemberInfo fi, Object target, Object value)
   at System.Runtime.Serialization.FormatterServices.PopulateObjectMembers(Object obj, MemberInfo[] members, Object[] data)
   at Castle.DynamicProxy.Serialization.ProxyObjectReference.RecreateClassProxy(SerializationInfo info, StreamingContext context)
   at Castle.DynamicProxy.Serialization.ProxyObjectReference.RecreateProxy(SerializationInfo info, StreamingContext context)
   at Castle.DynamicProxy.Serialization.ProxyObjectReference..ctor(SerializationInfo info, StreamingContext context)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle._SerializationInvoke(Object target, SignatureStruct& declaringTypeSig, SerializationInfo info, StreamingContext context)
   at System.RuntimeMethodHandle.SerializationInvoke(Object target, SignatureStruct declaringTypeSig, SerializationInfo info, StreamingContext context)
   at System.Reflection.RuntimeConstructorInfo.SerializationInvoke(Object target, SerializationInfo info, StreamingContext context)
   at System.Runtime.Serialization.ObjectManager.CompleteISerializableObject(Object obj, SerializationInfo info, StreamingContext context)
   at System.Runtime.Serialization.ObjectManager.FixupSpecialObject(ObjectHolder holder)
   at System.Runtime.Serialization.ObjectManager.DoFixups()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
   at Microsoft.VisualStudio.DebuggerVisualizers.DebugViewerShim.PrivateCallback.DeserializeObject(Stream ms)
   at Microsoft.VisualStudio.DebuggerVisualizers.DebugViewerShim.PrivateCallback.DeserializeObject(Byte[] arr, Int32 startFrom)
   at Microsoft.VisualStudio.DebuggerVisualizers.DebugViewerShim.PrivateCallback.Microsoft.VisualStudio.DebuggerVisualizers.IVisualizerObjectProvider.GetObject()
   at MyCompany.VisualStudio.DebuggerVisualizers.MyEntityDialogDebuggerVisualizer.Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
   at Microsoft.VisualStudio.DebuggerVisualizers.DebugViewerShim.ManagedShim.DelegatedHost.CreateViewer(IntPtr hwnd, HostServicesHelper hsh, SafeProxyWrapper proxy)


The actual field types in the message "object of type 'x' cannot be converted to type 'y'" vary depending on the entity type. It appears that Castle.DynamicProxy.Serialization.ProxyObjectReference.RecreateClassProxy is confused about the order of the serialized fields.

I don't know if it makes any difference, but my entities have additional serializable fields (and corresponding properties) for non-persistable values ...

I have no idea how to debug this -- I don't think the NHibernate source includes the source to the Castle.DynamicProxy.Serialization.ProxyObjectReference class ...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 5:20 pm 
Beginner
Beginner

Joined: Wed Jun 29, 2005 10:40 am
Posts: 30
Location: denver, co
I also have experienced this problem. I think its more of an issue with Castle's DynamicProxy2 than NHibernate. They are using the FormatterServices.PopulateObjectMembers method, which deserializes all member fields based on order, rather than name. When new dynamic classes are created (your proxies), the order of members can (and often does) change.

The only workaround I've found is to implement ISerializable and handle the serialization/deserialization of your classes on your own.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 7:52 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
That's what I feared :-(

Thanks for the suggestion on implementing ISerializable, I'll give it a try ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.