我有一个现成的MVC 4应用程序使用AspNetSqlProfileProvider,配置是这样的:错误加载ASP.Net档案
<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>
现在我想更新系统(而不删除旧的配置文件)是这样的:
<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>
我没有问题在以前的项目中添加额外的属性。如果序列化数据来自其中未定义附加属性的先前版本,则加载该属性 产生默认(T)。然而,随着这种变化,当我的控制器执行这一行:
List<MyTypeA> myTypeAs =
(List<MyTypeA>)HttpContext.Current.Profile.GetPropertyValue("MyTypeA");
一个异常被抛出:
Attempting to load this property's type resulted in the following error: Could not load type 'System.Collections.Generic.HashSet`1[System.Int32]'.
注意到,我引用List<MyTypeA>
类型的属性,但异常说,它无法加载类型
System.Collections.Generic.HashSet`1[System.Int32].
我在如何在web.config中指定类型时犯了错误吗?还有其他原因吗?
所有这些都发生在选择了.NET 4运行时的Visual Studio 2010 SP1中。