473,566 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XmlSerializatio n of objects in asp.net platform

1 New Member
Im trying to serialize to XMl some objects and it gives me the following errors :
An unhandled exception of type 'System.Invalid OperationExcept ion' occurred in System.Xml.dll

Additional information: There was an error reflecting type 'Serialization. Actor'.

Here my code:
class Program
{
static void Main(string[] args)
{
Actor actor = new Actor();
XmlSerializer serializer = new
XmlSerializer(t ypeof(Actor));
TextWriter tw = new
StreamWriter(@" C:\Users\admin\ Desktop\Exercis es\Serializatio n\program.xml") ;
serializer.Seri alize(tw, actor);

Actor bill = new Actor();
bill.Actor_Id = "10"; bill.Actor_Name = "Bill";
bill.Actor_Last Name = "Aktinson";
bill.ActorPhoto = System.Text.Enc oding.UTF8.GetB ytes(" ");
bill.ActorBirth Date = DateTime.Parse( "1990/01/15");
tw.Close();


XmlSerializer deserializer = new XmlSerializer(t ypeof(Actor));
TextReader reader = new StringReader(@" C:\Users\admin\ Desktop\Exercis es\Serializatio n\program.xml") ;
object obj = deserializer.De serialize(reade r) as object;
actor = (Actor)obj;
/*Actor Actor;
Console.WriteLi ne("ActorId: " + Actor.Actor_Id) ;
Console.WriteLi ne("ActorName: " + Actor.Actor_Nam e);
Console.WriteLi ne("ActorLastNa me: " + Actor.Actor_Las tName);
Console.WriteLi ne("ActorPhoto : " + Actor.ActorPhot o);
Console.WriteLi ne("ActorBirthd ay: " + Actor.ActorBirt hDate);
*/
reader.Close();



}

Actor.cs code :
using System;
using System.Collecti ons.Generic;
using System.Runtime. Serialization;

namespace Serialization
{


[Serializable()]
public partial class Actor : ISerializable
{
[System.Diagnost ics.CodeAnalysi s.SuppressMessa ge("Microsoft.U sage", "CA2214:DoNotCa llOverridableMe thodsInConstruc tors")]


public Actor()
{
this.Episode_Ac tors = new HashSet<Episode _Actors>();
}

public string Actor_Id { get; set; }
public string Actor_Name { get; set; }
public string Actor_LastName { get; set; }
public byte[] ActorPhoto { get; set; }
public Nullable<System .DateTime> ActorBirthDate { get; set; }

[System.Diagnost ics.CodeAnalysi s.SuppressMessa ge("Microsoft.U sage", "CA2227:Collect ionPropertiesSh ouldBeReadOnly" )]
public virtual ICollection<Epi sode_Actors> Episode_Actors { get; set; }

public void GetObjectData(S erializationInf o info, StreamingContex t context)
{
info.AddValue(" A_ID", Actor_Id);
info.AddValue(" A_Name", Actor_Name);
info.AddValue(" A_LastName",Act or_LastName);
info.AddValue(" A_Photo", ActorPhoto);
info.AddValue(" A_BirthDate", ActorBirthDate) ;
}
public Actor(Serializa tionInfo info, StreamingContex t context)
{
Actor_Id = (string)info.Ge tValue("A_ID", typeof(string)) ;
Actor_Name = (string)info.Ge tValue("A_Name" , typeof(string)) ;
Actor_LastName = (string)info.Ge tValue("A_LastN ame", typeof(string)) ;
ActorPhoto= (byte[])info.GetValue( "A_Photo", typeof(byte[]));
ActorBirthDate = (DateTime)info. GetValue("A_ID" , typeof(DateTime ));
}
}

}
Jan 5 '19 #1
0 1890

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3446
by: STom | last post by:
I have just started reading up on XMLSerialization and still do not understand the practical use of this technology. For example, if I have to know the class type on the client and on the web service side, wouldn't it be easier to just use .Net remoting? I envision some point of passing over the XML document but the web service not really...
3
3093
by: Boris Leykekhman | last post by:
Hi All, What is advantages/disadvantages of using XmlSerialization vs SoapSerialization? I'm specifically interested in "stability": I mean, I serialized something in a file and have to be sure that in a year, when the .Net version will be different, I still can deserialize my objects from this file. Thanks in advance Boris
0
2045
by: A programmer desperatly needing help! | last post by:
I use the xmlserialization on asp.net pages and on previous machines it never gave a problem. But now i somethings get a: Timed out waiting for a program to execute. The command being executed was "c:\winnt\microsoft.net\framework\v1.1.4322\csc.exe" /noconfig @"C:\DOCUME~1\...\ve3y0f-a.cmdline" error. It happens at random but occurs mostly...
3
2023
by: jerry_wu | last post by:
Hi how can i do for this proble I want to serialize data to a file We can use XmlSerialization in PC platform , as below 'Create a serialize Dim serializer As New XmlSerializer (Me.GetType serializer.Serialize(...
2
1560
by: Water Cooler v2 | last post by:
I create a test Web service like so: public class ServiceThingy: System.Web.Services.WebService { public int ReturnFour() { return 4; }
4
3973
by: pfrisbie | last post by:
I am developing a Web Services interface with C# and our partner is using Java (Axis 1.1). They require me to include xsi:types in the SOAP Messages I send them. For example: <Partner xmlns="urn:partner.xxxxx.com"> <RequestID>239</RequestID> <TimeStamp>2006-03-06T17:10:51.4662331-06:00</TimeStamp> <Subject...
1
3939
by: Frank | last post by:
Hi, Let's say I have a file named myFile.xml Within that file I have blocks of data which I'd like to add at different times during the day. e.g. <LogEntry>
0
1463
by: =?Utf-8?B?R2FyeQ==?= | last post by:
I have Line, Rect, and Ellipse classes derived from IShape interface, and am using the generic list, List<IShape>, to store a bunch of objects. When I used XMLSerializer object to serialize this list, got the error message: "Cannot serialize interface". However, I could use BinaryFormatter to serialize and deserialize the list. My question...
4
7101
by: =?Utf-8?B?Qnlyb24=?= | last post by:
When I try to serialize an instance of the LocationCell below (note Building field) I get an error in the reflection attempt. If I remove the _Building field it serializes fine. I tried renaming Building._Name to Building._BName in case the duplicate name was the issue, but that didn't help. Is there a native way to serialize nested...
1
2136
by: DesperateDan | last post by:
I've got a parent object that is a collection and it in turn is hosting 2 child objects. My searlization has worked perfectly to plan in as much that I wanted to dictate the names of the objects and properties via XMLatrributes with a prefix of "THE_.."....except for the name of the child objects. This should say THE_NEW_Child but instead...
0
7888
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7951
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2083
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1201
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
925
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.