Error Loading ASP.Net Profile

偶尔善良 提交于 2020-02-06 12:32:27

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/11680599/error-loading-asp-net-profile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!