-----------------------------------------------------------
New Message on MumbaiUserGroup
-----------------------------------------------------------
From: kakkirenivenkatesh
Message 1 in Discussion
Hi All, I am facing a problem when i am trying to serialize using
XMLSerialization. I have my main base class Account
using System;
using System.Xml.Serialization;
namespace BankLibrary
{
public class Account
{
public int accnumber;
public string holdername;
public decimal balance;
public Account(int acnum,string hname,decimal bal)
{
accnumber = acnum;
holdername = hname;
balance = bal;
}
public Account()
{ }
public virtual void withdraw(decimal amt)
{
balance -= amt;
}
public virtual void deposit(decimal amt)
{
balance += amt;
}
}
} Now i have two derived classes from Account. i.e. SavingAccount.cs and
CurrentAccount.cs SavingAccount.cs file contains following code:
using System;
namespace BankLibrary
{
public class SavingAccount:Account
{
public decimal MinimumBalance;
public SavingAccount(int acNum,string hName,decimal bal,decimal
ovl):base(acNum,hName,bal)
{
MinimumBalance = ovl;
}
public override void withdraw(decimal Amt)
{
if((balancep-Amt)<MinimumBalance)
{
MeaageBox.Show("You do not have sufficient funds to withdraw this amount.");
}
else
{
balancep -= Amt;
}
}
public override void deposit(decimal Amt)
{
balancep += Amt;
}
}
} CurrentAccount.cs file contains following code:
using System;
namespace BankLibrary
{
public class CurrentAccount:Account
{
private decimal OverDraftLimit;
public CurrentAccount(int acNum,string hName,decimal bal,decimal ovl) :
base(acNum,hName,bal)
{
OverDraftLimit = ovl;
}
public override void withdraw(decimal Amt)
{
if((balance-Amt+OverDraftLimit)>=0)
{
balance -= Amt;
}
else
{
MessageBox.Show("You do not have sufficient funds.");
}
}
public override void deposit(decimal Amt)
{
balance += Amt;
}
}
}
Now i have fourth class which contains ArrayList which can store Both
SavingAccount and CurrentAccount objects.
data.cs (filename)
using System;
using BankLibrary;
using System.Collections;
using System.Xml.Serialization;
using System.Xml;
namespace BankGUIClient
{
[Serializable ]
public class data
{
[XmlArray("Account")]
[XmlArrayItem("SavingsAccount",typeof(SavingAccount))]
[XmlArrayItem("CurrentAccount",typeof(CurrentAccount))]
public ArrayList objects = new ArrayList();
public data()
{
}
public void addobj(Account ac)
{
objects.Add(ac);
}
}
}
Now i am trying to serialize the objects by using XMLSerializer in a windows
form
private void SavetoFile_Click(object sender, System.EventArgs e)
{
FileStream fs = new
FileStream(@"C:\Synergetics\Venkat\MyADSolution\Data.xml",FileMode.Create);
XmlSerializer xs = new XmlSerializer(typeof(data));
xs.Serialize(fs,da);
fs.Close();
} now it is giving an exception: An unhandled exception of type
'System.InvalidOperationException' occurred in system.xml.dll Additional
information: There was an error reflecting type 'BankGUIClient.data'. Can
some one please help in this... i have tried all possibilities shown on the
net and i could not complete it... my mail id is [EMAIL PROTECTED]
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/mumbaiusergroup/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]