views:

49

answers:

1

Hi All,

I have a problem that I'm working in nHibernate project that have the following object:

[Serializable]
public class Prototype
{
    public virtual long Id { get; private set; }
    public virtual string Name { get; set; }   
    public virtual IList<AttributeGroup> AttributeGroups { get; private set; }
}

and I have created a method to deserialize an XML file and put it into object of type Prototype as following :

public static T Deserialize(string fileName)
{
    XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
    XmlTextReader xmlTextReader = new XmlTextReader(fileName);
    Object c = xmlSerializer.Deserialize(xmlTextReader);
    return (T)c;
}

The problem now that I have the following exception

Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericBag`1[BCatalog.Entities.AttributeGroup]' to type 'System.Collections.Generic.List`1[BCatalog.Entities.AttributeGroup]'.

I can't change the type of the IList because of the nHibernate and I want to deserialize the object

what should I do to solve this problem ?

please answer me as soon as you can

Thanks in Advance

A: 

Looks like you have the same problem this person had.

Russell McClure
I don't think so. He already has the IList`1. I think this problem has something to do with code or data that's not in the question.
Pieter
I see the IList in the class definition, but the error makes it pretty clear that the code is trying to cast it as a List. You are right though, the offending line of code is not (currently) in the problem description.
Russell McClure