Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6070467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:56:13+00:00 2026-05-23T09:56:13+00:00

I have a problem that I’m working in nHibernate project that have the following

  • 0

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; }
}

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 is 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 ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:56:13+00:00Added an answer on May 23, 2026 at 9:56 am

    Interfaces seems to be cumbersome for serialization/deserialization processes. You might need to add another public member to the class that uses a concrete type and mark the interface property as xml ignore. This way you can deserialize the object without loosing your contract base.

    Something like the following:

    [Serializable]
    public class Prototype
    {
        public virtual long Id { get; private set; }
        public virtual string Name { get; set; }   
        [XMLIgnore]
        public virtual IList<AttributeGroup> AttributeGroups { 
            get { return this.AttributeGroupsList; } 
        }
        public virtual List<AttributeGroup> AttributeGroupsList { get; private set;}
    }
    

    For more information about deserialization attributes please check XmlAttributes Properties.

    Regards,

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem that when I try to save an object in the
I have a problem that i've struggled with for a long time. This problem
I have following problem that in a transformation (which is completely done in memory)
In a couple of scripts that I use I have problem that is intermittent.
I have a problem that I have not seen addressed in this particular way
I have the problem that add_custom_command is always out of date and therefore runs
I have a problem that confuses my users, being that although an item is
I have the problem that an specific step in Ant can only be executed
I have a problem that I would like have solved via a SQL query.
I have a problem that I feel is best implimented in a stand alone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.