Declaring a Class in ASPX Script Block Then Storing it in Session
<p>I am having trouble doing something that I think should be very doable. Perhaps someone can tell me what I'm missing.
I am restricted to adding my C# code to my .aspx page in a server-side script block (no code behind). I would like to define a new class (again without creating any other files) on the ASPX page (this would be a nested class) and then store a List of these objects in Session to persist between postbacks and after the user spends some time on other pages and then returns to the one in question.
Here's my code...</p>

<pre><code>    &lt;script language="C#" runat="Server"&gt;
    protected List&lt;Part&gt; AssignmentSearchResults
    {
        get
        {
            if (Session["SearchResults"] == null)
                Session["SearchResults"] = new List&lt;Part&gt;();
            return (List&lt;Part&gt;)Session["SearchResults"];
        }
        set
        {
            Session["SearchResults"] = value;
        }
    }

    public class Part
    {
        public string Id { get; set; }
        public string Description { get; set; }
        public string Type { get; set; }
        public bool Selected { get; set; }
    }

&lt;/script&gt;
(html goes here)
</code></pre>

<p>If I use List it works just fine, but when I use my custom class it does not. Here is the error I get...</p>

<blockquote>
  <p>[A]System.Collections.Generic.List<code>1[ASP.pub_usercontrols_exeplanning_resources_ascx+Part] cannot be cast to [B]System.Collections.Generic.List</code>1[ASP.pub_usercontrols_exeplanning_resources_ascx+Part]. Type A originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. Type B originates from 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' in the context 'LoadNeither' at location 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'.</p>
</blockquote>

<p>...and perhaps you'll note that the two (A and B) are completely identical.
Any ideas? Thanks a lot in advance for any help.</p>
