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 ));
}
}
}
0 1894 Sign in to post your reply or Sign up for a free account.
Similar topics |
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 knowing about the objects type.
Am I way off base with my perceptions?
|
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
|
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 when calling the
XMLserialization multiple time rapidly.
While looking at the .out file the error...
|
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(...
|
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;
}
| |
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 xmlns:ns1="urn:partnermapping.xxxxxx.com"
xsi:type="ns1:PartnerMapping">
<AccountID>98401</AccountID>
|
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>
|
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 is that is it possible to serialize the bunch of objects through
XMLSerializer?
I know it seems...
|
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 objects, or will I have to write
my own?
public class LocationCell
|
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 still persist in saying
"NewChild" (Child properties are as planned)
What's the solution?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |