我的对象是如何进入ASP.NET页面状态的?

时间:2010-03-23 19:57:35

标签: c# nhibernate serialization

我知道这个错误是什么,如何修复它等等。

我的问题是,我不知道为什么我正在开发的当前页面在我不以任何方式直接使用foo类时抛出此错误,我也没有向viewstate设置任何内容。我正在使用回发很多,但就像我说的,我没有在viewstate中存储任何东西等一个整数。

如果相关,我正在使用nhibernate。

我知道为什么我需要将这些类标记为可序列化而不使用?我应该在哪里开始调查?

[SerializationException: Type 'FlexiCommerce.Persistence.NH.ContentPersister' in Assembly 'FlexiCommerce.Persistence.NH, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.]
   System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type) +9434541
   System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context) +247
   System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo() +160
   System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder) +218
   System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo) +388
   System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +444
   System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +133
   System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph) +13
   System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value) +2937

[ArgumentException: Error serializing value 'Music#2' of type 'FlexiCommerce.Components.Category.']
   System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value) +3252
   System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value) +2276

[ArgumentException: Error serializing value 'System.Object[]' of type 'System.Object[].']
   System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer, Object value) +3252
   System.Web.UI.ObjectStateFormatter.Serialize(Stream outputStream, Object stateGraph) +116
   System.Web.UI.ObjectStateFormatter.Serialize(Object stateGraph) +57
   System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Serialize(Object state) +4
   System.Web.UI.Util.SerializeWithAssert(IStateFormatter formatter, Object stateGraph) +37
   System.Web.UI.HiddenFieldPageStatePersister.Save() +79
   System.Web.UI.Page.SavePageStateToPersistenceMedium(Object state) +108
   System.Web.UI.Page.SaveAllState() +315
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2492

2 个答案:

答案 0 :(得分:2)

您是否可能数据绑定此类对象?它显然已经以某种方式进入了页面状态。

答案 1 :(得分:0)

我认为你已经启用了一些缓存元素用于查询缓存,或者启用了NHibernate的实际对象图缓存(如果可能的话,使用SysCacheProvider只是HttpRuntime.Cache)。

无论是否使用缓存,我都会建议将每个Domain对象标记为可序列化,因为它在某些时候非常合理,它将通过线路或仅进入ViewState / Session容器。