我有一个使用 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>

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

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

抛出异常:

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

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

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

我在 web.config 中指定类型时犯了错误吗?难道还有别的原因吗?

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

有帮助吗?

解决方案

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

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top