Alvin Bruney said:
what does your isearlizable implementation look like? can you post a short
but complete program demonstrating the issue? Short but complete is
defined here
http://www.yoda.arachsys.com/csharp/complete.html
Thanks Alvin,
Let me explain exactly what my sample program is doing.
1. I created a new class called MyHashtable, which inherits Hashtable.
2. The first time the page is loaded I instatiate a new MyHashtable object
and store it in ViewState.
3. Then I display the object type in the literal control. It is shown as
type MyHashtable.
4. I click the button
5. The object type is again shown in the literal control. But instead of
the expected MyHashtable type, it is shown as Hashtable (the base class).
Please notice in the code below, ISerializable is implemented for
MyHashtable. I believe this is necessary to accomplish my objective, but
please be aware the same thing happens even if the class is empty, like so:
public class MyHashtable : Hashtable {}
I know this is something disgustingly simple, but I can't figure out what.
Any help is appreciated. Please find code below.
Regards,
John
----------------------------
-- MyHashtable.cs
----------------------------
using System;
using System.Collections;
using System.Runtime.Serialization;
namespace DerivedHashTable
{
[Serializable]
public class MyHashtable : Hashtable, ISerializable
{
private int irrelevantVar; // misc variable
public MyHashtable() : base() {}
public MyHashtable(SerializationInfo info, StreamingContext context)
: base( info, context)
{
irrelevantVar = info.GetInt32( "irrelevantVar");
}
public override void GetObjectData(SerializationInfo info,
StreamingContext context)
{
base.GetObjectData(info,context);
info.AddValue( "irrelevantVar", irrelevantVar);
}
}
}
----------------------------
----------------------------
WebForm1.aspx
----------------------------
<%@ Page language="c#" %>
<%@ Import namespace="DerivedHashTable" %>
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
ViewState["MyHashtable"] = new MyHashtable();
lit.Text = "Object type name = " +
ViewState["MyHashtable"].GetType().Name;
}
</script>
<html>
<body>
<form id="Form1" method="post" runat="server">
<asp:Literal ID="lit" Runat="server"/><br>
<asp:Button Text="Postback" Runat="server"/>
</form>
</body>
</html>