PDA

View Full Version : سوال: مشکل در پیاده سازی Iserializable



sunny_sh
شنبه 15 تیر 1387, 20:00 عصر
سلام خدمت همه دوستان.
من یک کلاس نوشتم که این کلاس را می خواستم به Object تبدیل کنم که بعد از جستجو تو Google به این نتجه رسید که باید ISerializable پیاده سازی کنم اما بعد از اجرا باز با خطا مواجه می شم :عصبانی++::گریه:




using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;


[Serializable()]
public class calculatores :ISerializable
{
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
throw new System.ArgumentNullException("info");
info.SetType(typeof(calculatores));
if (info != null)
{
info.AddValue("Array", Array);
//info.AddValue("HaveMemory" typeof(MemoryDelegat));
//info.AddValue("HaveNotMemory", typeof(MemoryDelegat));
info.AddValue("memory", memory);
//info.AddValue("Memory", memory);
//info.AddValue("Result", Result);
info.AddValue("Value", Value);
}
}
/*
protected calculatores(SerializationInfo info, StreamingContext contex)
{
}*/
private float Value;
public ArrayList Array = new ArrayList();
private float memory;
public event MemoryDelegat HaveMemory;
public event MemoryDelegat HaveNotMemory;
public delegate void MemoryDelegat();
public float Memory
{
get
{
return memory;
}
set
{
memory = value;
}
}
public string Result
{
get
{
return Value.ToString(); ;
}
set
{
float temp = 0;
if (float.TryParse(value, out temp))
{
Value = temp;
}
else
{
temp = 0;
Value = temp;
}
}
}
public void Clear()
{
Value = 0;
ResetMemory();
}
public void AddMemory(string strValue)
{
float temp = 0;
if (float.TryParse(strValue, out temp))
{
memory += temp;
if (this.HaveMemory != null)
{
this.HaveMemory();
}
}
}
public void SubMemory(string strValue)
{
float temp = 0;
if (float.TryParse(strValue, out temp))
{
memory -= temp;
if ((this.HaveNotMemory != null)&& (this.memory ==0))
{
this.HaveNotMemory();
}
}
}
public void ResetMemory()
{
memory = 0;
if (this.HaveNotMemory != null)
{
this.HaveNotMemory();
}
}
public calculatores()
{

Value = 0;
Array.Add((0).ToString());
}
public calculatores(float flttValue)
{
Value = flttValue;
Array.Add(flttValue);
}
/*public calculatores(SerializationInfo info, StreamingContext context)
{
Value = info.GetInt32( "Value");
}*/
public string Add(string strValue)
{
float temp = 0;
if (float.TryParse(strValue, out temp))
{
Value += temp;
Array.Add("+");
Array.Add(Value.ToString());
}
return Value.ToString();
}
public string Sub(string strValue)
{
float temp = 0;
if (float.TryParse(strValue, out temp))
{
Value -= temp;
Array.Add("-");
Array.Add(Value.ToString());
}
return Value.ToString();
}
/*public override string ToString()
{
return Value.ToString();
}*/

public static string Foat2string(string strValue,string strconcatvalue)
{
float temp1 = 0, temp2 = 0 ,Zero=0.0f;
if (float.TryParse(strValue, out temp1) && (float.TryParse(strconcatvalue, out temp2)))
{
if(temp1 == Zero)
return temp2.ToString();
else
return temp1.ToString()+temp2.ToString();
}
return temp1.ToString();
}

}


و اما این خطا زیر را می دهد، ممنون از راهنماییتون.



The state information is invalid for this page and might be corrupted.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The state information is invalid for this page and might be corrupted.

Source Error:

[No relevant source lines]
Source File: i:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET Files\calculator2\bee2b328\6ab4e751\App_Web_zzefjy q_.0.cs Line: 0

Stack Trace:

[SerializationException: The constructor to deserialize an object of type 'calculatores' was not found.] System.Runtime.Serialization.ObjectManager.GetCons tructor(Type t, Type[] ctorParams) +2798357 System.Runtime.Serialization.ObjectManager.Complet eISerializableObject(Object obj, SerializationInfo info, StreamingContext context) +99[SerializationException: The constructor to deserialize an object of type 'calculatores' was not found.] System.Runtime.Serialization.ObjectManager.Complet eISerializableObject(Object obj, SerializationInfo info, StreamingContext context) +237 System.Runtime.Serialization.ObjectManager.FixupSp ecialObject(ObjectHolder holder) +49 System.Runtime.Serialization.ObjectManager.DoFixup s() +167 System.Runtime.Serialization.Formatters.Binary.Obj ectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +203 System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +190 System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Deserialize(Stream serializationStream) +12 System.Web.UI.ObjectStateFormatter.DeserializeValu e(SerializerBinaryReader reader) +2800 System.Web.UI.ObjectStateFormatter.DeserializeValu e(SerializerBinaryReader reader) +601 System.Web.UI.ObjectStateFormatter.DeserializeValu e(SerializerBinaryReader reader) +338 System.Web.UI.ObjectStateFormatter.DeserializeValu e(SerializerBinaryReader reader) +358 System.Web.UI.ObjectStateFormatter.DeserializeValu e(SerializerBinaryReader reader) +338 System.Web.UI.ObjectStateFormatter.Deserialize(Str eam inputStream) +223[ArgumentException: The serialized data is invalid.] System.Web.UI.ObjectStateFormatter.Deserialize(Str eam inputStream) +309 System.Web.UI.ObjectStateFormatter.Deserialize(Str ing inputString) +394 System.Web.UI.ObjectStateFormatter.System.Web.UI.I StateFormatter.Deserialize(String serializedState) +30 System.Web.UI.Util.DeserializeWithAssert(IStateFor matter formatter, String serializedState) +52 System.Web.UI.HiddenFieldPageStatePersister.Load() +155[ViewStateException: Invalid viewstate. Client IP: 127.0.0.1 Port: User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022) ViewState: /wEPDwULLTE5NDEwNTIxOTIPFgIeAVgynAIAAQAAAP////8BAAAAAAAAAAwCAAAASEFwcF9Db2RlLnNxMXVudGltLCBWZXJz aW9uPTAuMC4wLjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2 V5VG9rZW49bnVsbAUBAAAADGNhbGN1bGF0b3JlcwMAAAAFQXJy YXkGbWVtb3J5BVZhbHVlAwAAHFN5c3RlbS5Db2xsZWN0aW9ucy 5BcnJheUxpc3QLCwIAAAAJAwAAAAAAAAAAAAAABAMAAAAcU3lz dGVtLkNvbGxlY3Rpb25zLkFycmF5TGlzdAMAAAAGX2l0ZW1zBV 9zaXplCF92ZXJzaW9uBQAACAgJBAAAAAEAAAABAAAAEAQAAAAE AAAABgUAAAABMA0DCxYCAgMPZBYCAgEPDxYCHgRUZXh0BQEwFg IeCm9ua2V5UHJlc3MFG3JldHVybiBDaGVja0tleUNvZGUoZXZl bnQpO2RkSYVMT+IhYRkVTSKbW+azloObB3E= Referer: http://localhost:1156/Calculator2/ Path: /Calculator2/default.aspx][HttpException (0x80004005): The state information is invalid for this page and might be corrupted.] System.Web.UI.ViewStateException.ThrowError(Except ion inner, String persistedState, String errorPageMessage, Boolean macValidationError) +171 System.Web.UI.ViewStateException.ThrowViewStateErr or(Exception inner, String persistedState) +37 System.Web.UI.HiddenFieldPageStatePersister.Load() +269 System.Web.UI.Page.LoadPageStateFromPersistenceMed ium() +137 System.Web.UI.Page.LoadAllState() +102 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5900 System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +281 System.Web.UI.Page.ProcessRequest() +112 System.Web.UI.Page.ProcessRequestWithNoAssert(Http Context context) +37 System.Web.UI.Page.ProcessRequest(HttpContext context) +135 ASP.default_aspx.ProcessRequest(HttpContext context) in i:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temp orary ASP.NET Files\calculator2\bee2b328\6ab4e751\App_Web_zzefjy q_.0.cs:0 System.Web.CallHandlerExecutionStep.System.Web.Htt pApplication.IExecutionStep.Execute() +715 System.Web.HttpApplication.ExecuteStep(IExecutionS tep step, Boolean& completedSynchronously) +117