Using a profile property of type List in .NET Membership
Asked Answered
C

1

7

I'm working on a C# Webservice that needs to provide authentication as well as roles and profile management. I need each profile to have a property of type List. The profile section in the web.config looks like this:

<profile defaultProvider="MyProfileProvider" enabled="true">
  <providers>
    <remove name="MyProfileProvider"/>
    <add connectionStringName="MySqlServer"
      applicationName="MyApp"
      name="MyProfileProvider"
      type="System.Web.Profile.SqlProfileProvider" />
  </providers>
  <properties>
    <add name="Websites" type="System.Collections.Generic.List&lt;String&gt;" serializeAs="Binary"/>
  </properties>
</profile> 

However, when I start the webservice and try to access that property it returns the following error:

System.Configuration.ConfigurationErrorsException: Attempting to load this property's type resulted in the following error: Could not load type 'System.Collections.Generic.List<String>'. (C:\Projects\MyProject\web.config line 58) ---> System.Web.HttpException: Could not load type 'System.Collections.Generic.List<String>'.

Is there a way to use a generic collection for this purpose?

Chambliss answered 4/2, 2010 at 11:56 Comment(0)
C
11

After more searching I finally managed to find the answer. The solution is to use the type name qualified by its namespace. This means that for my issue I used:

<add name="Websites" type="System.Collections.Generic.List`1[System.String]" serializeAs="Binary"/>

I also found out that it is also possible to specify classes defined in other assemblies. To use those you need the assembly-qualified name. For example, that would be "System.Collections.Generic.HashSet`1[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" for a Hashset of Strings.

Chambliss answered 4/2, 2010 at 14:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.