0

我有一个使用 AspNetSqlProfileProvider 的现有 MVC 4 应用程序,配置如下:

<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>

在以前的项目中添加其他属性没有问题。如果序列化数据来自未定义附加属性的先前版本,则加载该属性会产生 default(T)。但是,通过此更改,当我的控制器执行此行时:

List<MyTypeA> myTypeAs = 
     (List<MyTypeA>)HttpContext.Current.Profile.GetPropertyValue("MyTypeA");

抛出异常:

尝试加载此属性的类型导致以下错误:无法加载类型“System.Collections.Generic.HashSet`1[System.Int32]”。

请注意,我正在引用类型的属性,List<MyTypeA>但异常说它无法加载类型

System.Collections.Generic.HashSet`1[System.Int32]。

我在 web.config 中指定类型的方式有误吗?还有其他原因吗?

所有这一切都发生在选择了 .NET 4 运行时的 Visual Studio 2010 SP1 中。

4

1 回答 1

0

事实证明,与 不同List<T>,它HashSet<T>需要一个完全限定的程序集名称。

System.Collections.Generic.HashSet`1[[System.Int32]],System.Core,版本=4.0.0.0,文化=中性,PublicKeyToken=b77a5c561934e089

于 2012-07-27T05:29:02.057 回答