I have an existing MVC 4 application that uses the AspNetSqlProfileProvider, configured like this:
<properties>
<add name="MyTypeAs"
type="System.Collections.Generic.List`1[[My.Namespace.MyTypeA, My.Namespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]" serializeAs="Binary" />
</properties>
Now I wish to update the system (without removing the old profiles) like this:
<properties>
<add name="MyTypeAs"
type="System.Collections.Generic.List`1[[My.Namespace.MyTypeA, My.Namespace, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]" serializeAs="Binary" />
<add name="MyHashOfInts"
type="System.Collections.Generic.HashSet`1[System.Int32]" serializeAs="Binary" />
</properties>
I have had no problem adding additional properties in previous projects. If the serialized data was from a previous version where the additional property was not defined, loading that property yielded default(T). However, with this change, when my controller executes this line:
List<MyTypeA> myTypeAs =
(List<MyTypeA>)HttpContext.Current.Profile.GetPropertyValue("MyTypeA");
an Exception is thrown:
Attempting to load this property's type resulted in the following error: Could not load type 'System.Collections.Generic.HashSet`1[System.Int32]'.
Notice that I'm referencing a property of type List<MyTypeA>
but the Exception says it cannot load the type
System.Collections.Generic.HashSet`1[System.Int32].
Did I make a mistake in how I specified the type in web.config? Is there another cause?
All of this is happening in Visual Studio 2010 SP1 with the .NET 4 runtime selected.
It turns out that, different from List<T>
, HashSet<T>
requires a fully qualified assembly name.
System.Collections.Generic.HashSet`1[[System.Int32]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089