Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello everybody, I am work on the asp.net Profile and currently I am trying to work on the multiple properties to showing in the form page using table's but when I run the application then it shows the this following error:
Using the generic type 'System.Collections.Generic.List<T>' requires '1' type arguments


For this application I had wrote this code:

XML
<anonymousIdentification enabled="true"/>
  <profile automaticSaveEnabled="false">

    <properties>
      <add name="Products" allowAnonymous="true" type="System.Collections.Generic.List[BusinessObject.Products]" serializeAs="Xml"/>
      <!--<add name="Id" type="int" allowAnonymous="true"/>
      <add name="Name" type="String" allowAnonymous="true" />
      <add name="ImageUrl" type="String" allowAnonymous="true"/>
      <add name="Price" type="int" allowAnonymous="true"/>
      <add name="Item" type="int" allowAnonymous="true" />-->

    </properties>
 </profile>


It seems the problem in the "Type" which I had declare inside the property but I don't get an any idea how to resolve it.Here's in this code the "BusinessObject is the namespace and the "Products" is the class name.So please help me to resolve this problem and tell me its appropriate solution.Help me please.
Posted
Updated 9-Oct-14 1:42am
v2
Comments
BillWoodruff 9-Oct-14 8:31am    
I'm not deep enough into XML to speak with any authority here, but try:

System.Collections.Generic.List<businessobject.products>

1 solution

You might be able to get away with specifying the correct generic type name:
System.Collections.Generic.List`1[BusinessObject.Products]

However, the simplest solution would be to use a custom non-generic collection class:
C#
using System;
using System.Collections.Generic;

namespace BusinessObject
{
    public class ProductsCollection : List<Products>
    {
        public ProductsCollection(IEnumerable<Products> collection) : base(collection)
        {
        }
        
        public ProductsCollection(int capacity) : base(capacity)
        {
        }
        
        public ProductsCollection()
        {
        }
    }
}
 
Share this answer
 
Comments
BillWoodruff 9-Oct-14 9:04am    
Do you think the problem here may be the use of square brackets [] rather than <> ?
Richard Deeming 9-Oct-14 9:21am    
Everything I've seen says to use square brackets. I think the OP was just missing the "`1" between the type name and type parameters.
BillWoodruff 9-Oct-14 17:18pm    
Thanks; obviously I should have kept my mouth shut :)
AnoopGharu 10-Oct-14 3:59am    
Thank you So much Sir for your best concerned, anyway can you tell me please why you had to use "`1" in the Generic List and I have these above properties which I had already declared in the comments inside the profile.Can you tell me please how I need to define my these properties in the new PorductsCollection class with the use of Enumeration or without the use of it.Please help me because I am new to asp.net.
Richard Deeming 10-Oct-14 4:09am    
The "`1" is added to the name of a generic type to indicate the number of type parameters. This "name mangling" allows compilers to support multiple generic types with the same name but a different number of parameters. For more information, look at the remarks of the Type.GetType method[^] on MSDN.

If you go with a custom non-generic collection class, you don't need to specify the generic type parameters. You would just declare your property's type as "BusinessObject.ProductsCollection". Since the collection class is derived from List<BusinessObject.Products>, you shouldn't need to change any code that reads it. Only code that assigns a new value to the property would need to change.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900