InvalidOperationException was unhandled

InvalidOperationException was unhandled

Post by UHJhc2FkIE » Thu, 13 May 2004 13:31:02


am getting unhandled InvalidOperationException
Details : "There was an error generating the XML document for the statement
mySerializer.Serialize(writer, myGroup)
at line no.11
Please help me in execution of the following code. It should give output as given belo
.NE
10
5
5/2/2002 12:00:00 A
1000
Tru

Press any key to continu

Code

//<Snippet1
import System.*
import System.IO.*
import System.Text.*
import System.Xml.*
import System.Xml.Serialization.*
import System.Xml.Schema.*
public class Grou

/** @attribute SoapAttribute(Namespace = "http://www.cpandl.com"
* *
public String GroupName

/** @attribute SoapAttribute(DataType = "base64Binary"
* *
public System.Byte GroupNumber[]

/** @attribute SoapAttribute(DataType = "date", AttributeName = "CreationDate"
* *
public DateTime Today

/** @attribute SoapElement(DataType = "nonNegativeInteger", ElementName = "PosInt"
* *
public String PostitiveInt

// This is ignored when serialized unless it's overridden
/** @attribute SoapIgnore(
* *
public boolean IgnoreThis

public GroupType Grouptype

public Vehicle MyVehicle

// The SoapInclude allows the method to return a Car
/** @ attribute SoapInclude(Car.class.ToType()
* *
public Vehicle myCar(String licNumber

Vehicle v
if (licNumber.Equals("")

v = new Car()
v.licenseNumber = "!!!!!!"

els

v = new Car()
v.licenseNumber = licNumber

return v
} //myCa
} //Grou

// SoapInclude allows Vehicle to accept Car type
/** @ attribute SoapInclude(Car .class.ToType()
* *
abstract public class Vehicl

public String licenseNumber

public DateTime makeDate
} //Vehicl

public class Ca
extends Vehicl

} //Ca

public class GroupTyp

public int member

public GroupType(

member = 0


public GroupType(int n

member = n


/** @attribute SoapEnum("Small"
*
public static int A = 0

/** @attribute SoapEnum("Large"
*
public static int B = 1


public class Ru

public static void main(String[] args

Run test = new Run()
test.SerializeOriginal("SoapOriginal.xml")
test.SerializeOverride("SoapOverrides.xml")
test.DeserializeOriginal("SoapOriginal.xml")
test.DeserializeOverride("SoapOverrides.xml")
} //mai

public void SerializeOriginal(String filename

// Create an instance of the XmlSerializer class
XmlTypeMapping myMapping = (new SoapReflectionImporter()).ImportTypeMapping(Group.class.ToType())
XmlSerializer mySerializer = new XmlSerializer(myMapping)
Group myGroup = MakeGroup()
// Writing the file requires a TextWriter
XmlTextWriter writer = new XmlTextWriter(filename, Encoding.get_UTF8())
writer.set_Formatting(Formatting.Indented)
writer.WriteStartElement("wrapper")
// Serialize the class, and close the TextWriter
mySerializer.Serialize(writer, myGroup)
writer.WriteEndElement()
writer.Close()
} //SerializeOrigina

public void SerializeOverride(String filename

// Create an instance of the XmlSerializer clas
// that overrides the serialization
XmlSerializer overRideSer
 
 
 

InvalidOperationException was unhandled

Post by Lars-Inge » Sat, 15 May 2004 06:08:19

ow I get this output:

.NET
100
50
02.05.2002 00:00:00
10000
True

Please see // HERE_________


import System.*;
import System.IO.*;
import System.Text.*;
import System.Xml.*;
import System.Xml.Serialization.*;
import System.Xml.Schema.*;

public class Group
{
/** @attribute SoapAttribute(Namespace = http://www.cpandl.com) */
public String GroupName;

/** @attribute SoapAttribute(DataType = "base64Binary") */
public System.Byte GroupNumber[];

/** @attribute SoapAttribute(DataType = "date", AttributeName =
"CreationDate") */
public DateTime Today;

/** @attribute SoapElement(DataType = "nonNegativeInteger", ElementName
= "PosInt") */
public String PostitiveInt;

// This is ignored when serialized unless it's overridden.
/** @attribute SoapIgnore() */
public boolean IgnoreThis;
public GroupType Grouptype;
public Vehicle MyVehicle;
// The SoapInclude allows the method to return a Car.
/** @ attribute SoapInclude(Car.class.ToType()) */

public Vehicle myCar(String licNumber)
{
Vehicle v;
if (licNumber.Equals(""))
{
v = new Car();
v.licenseNumber = "!!!!!!";
}
else
{
v = new Car();
v.licenseNumber = licNumber;
}
return v;
} //myCar
} //Group
// SoapInclude allows Vehicle to accept Car type.

// HERE____________________________
/** @attribute SoapInclude(Car.class) */
public class Vehicle
{
public Vehicle()
{
}
public String licenseNumber;
public DateTime makeDate;
} //Vehicle
// _________________________________


public class Car extends Vehicle
{
} //Car

public class GroupType
{
public int member;
public GroupType()
{
member = 0;
}
public GroupType(int n)
{
member = n;
}
/** @attribute SoapEnum("Small") */
public static int A = 0;
/** @attribute SoapEnum("Large") */
public static int B = 1;
}

public class Run
{
public static void main(String[] args)
{
Run test = new Run();
test.SerializeOriginal("SoapOriginal.xml");
test.SerializeOverride("SoapOverrides.xml");
test.DeserializeOriginal("SoapOriginal.xml");
test.DeserializeOverride("SoapOverrides.xml");
} //main
public void SerializeOriginal(String filename)
{
// Create an instance of the XmlSerializer class.
XmlTypeMapping myMapping = (new
SoapReflectionImporter()).ImportTypeMapping (Group.class.ToType());
XmlSerializer mySerializer = new XmlSerializer(myMapping);
Group myGroup = MakeGroup();
// Writing the file requires a TextWriter.
XmlTextWriter writer = new XmlTextWriter(filename,
Encoding.get_UTF8());
writer.set_Formatting(Formatting.Indented);
writer.WriteStartElement("wrapper");
// Serialize the class, and close the TextWriter.
mySerializer.Serialize(writer, myGroup);
writer.WriteEndElement();
writer.Close();
} //SerializeOriginal

public void SerializeOverride(String filename)
{
// Create an instance of the XmlSerializer class
// that overrides the serialization.
XmlSerializer overRideSerializer = CreateOverrideSerializer();
Group myGroup = MakeGroup();
// Writing the file requires
 
 
 

InvalidOperationException was unhandled

Post by UHJhc2FkIE » Sat, 15 May 2004 15:16:02

I am getting unhandled InvalidOperationException at runtime for statemen
mySerializer.Serialize(writer, myGroup)
at line no. 6

Could anybody please helpout in excecuting this code

//<Snippet1
import System.*
import System.IO.*
import System.Xml.*
import System.Xml.Serialization.*

public class Grou

public String groupName
public GroupType groupType
} //Grou

public class GroupTyp

// Use the SoapEnumAttribute to instruct the XmlSerialize
// to generate Small and Large instead of A and B
public int member

public GroupType(

member = 0
} //GroupTyp

public GroupType(int n

member = n
} //GroupTyp

/** @attribute SoapEnum("Small"
*
public static int a = 0

/** @attribute SoapEnum("Large"
*
public static int B = 1
} //GroupTyp

public class Ru

public static void main(String[] args

Run test = new Run()
test.SerializeObject("SoapEnum.xml")
test.SerializeOverride("SoapOverride.xml")
Console.WriteLine("Fininished writing two files")
} //mai

private void SerializeObject(String filename

// Create an instance of the XmlSerializer Class
XmlTypeMapping mapp = (new SoapReflectionImporter())
ImportTypeMapping(Group.class.ToType())
XmlSerializer mySerializer = new XmlSerializer(mapp)
// Writing the file requires a TextWriter
TextWriter writer = new StreamWriter(filename)
// Create an instance of the Class that will be serialized
Group myGroup = new Group()
// Set the object properties
myGroup.groupName = ".NET"
myGroup.groupType = new GroupType(GroupType.a)
// Serialize the Class, and close the TextWriter
mySerializer.Serialize(writer, myGroup)
writer.Close()
} //SerializeObjec

private void SerializeOverride(String fileName

SoapAttributeOverrides soapOver = new SoapAttributeOverrides()
SoapAttributes SoapAtts = new SoapAttributes()
// Add a SoapEnumAttribute for the GroupType.a enumerator.
// Instead of 'A' it will be "West"
SoapEnumAttribute soapEnum = new SoapEnumAttribute("West")
// Override the "A" enumerator
SoapAtts.set_SoapEnum(soapEnum)
soapOver.Add(GroupType.class.ToType(), "A", SoapAtts)
// Add another SoapEnumAttribute for the GroupType.B enumerator
// Instead of //B// it will be "East"
SoapAtts = new SoapAttributes()
soapEnum = new SoapEnumAttribute()
soapEnum.set_Name("East")
SoapAtts.set_SoapEnum(soapEnum)
soapOver.Add(GroupType.class.ToType(), "B", SoapAtts)
// Create an XmlSerializer used for overriding
XmlTypeMapping map = (new SoapReflectionImporter(soapOver))
ImportTypeMapping(Group.class.ToType())
XmlSerializer ser = new XmlSerializer(map)
Group myGroup = new Group()
myGroup.groupName = ".NET"
myGroup.groupType = new GroupType(GroupType.B)
// Writing the file requires a TextWriter
TextWriter writer = new StreamWriter(fileName)
ser.Serialize(writer, myGroup)
writer.Close()
} //SerializeOverrid
} //Ru
//</Snippet1>
 
 
 

InvalidOperationException was unhandled

Post by Lars-Inge » Tue, 18 May 2004 21:28:46


Sorry, I did not see your post until now. Please try this one.

Please see // HERE_____

import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.Serialization.*;

public class Group
{
public String groupName;
public GroupType groupType;
} //Group

public class GroupType
{
public int member;
public GroupType()
{
member = 0;
} //GroupType

public GroupType(int n)
{
member = n;
} //GroupType

/** @attribute SoapEnum("Small") */
public static int a = 0;

/** @attribute SoapEnum("Large") */
public static int B = 1;
} //GroupType

public class Run
{
public static void main(String[] args)
{
Run test = new Run();
test.SerializeObject("SoapEnum.xml");
test.SerializeOverride("SoapOverride.xml");
Console.WriteLine("Fininished writing two files");
} //main

private void SerializeObject(String filename)
{
TextWriter writer = new StreamWriter(filename);
Group myGroup = new Group();
myGroup.groupName = ".NET";
myGroup.groupType = new GroupType(GroupType.a);

// HERE_________________
XmlSerializer mySerializer = new XmlSerializer( myGroup.GetType() );
// ______________________

mySerializer.Serialize(writer, myGroup);
writer.Close();
} //SerializeObject

private void SerializeOverride(String fileName)
{
SoapAttributeOverrides soapOver = new SoapAttributeOverrides();
SoapAttributes SoapAtts = new SoapAttributes();
SoapEnumAttribute soapEnum = new SoapEnumAttribute("West");
SoapAtts.set_SoapEnum(soapEnum);
soapOver.Add(GroupType.class.ToType(), "A", SoapAtts);
SoapAtts = new SoapAttributes();
soapEnum = new SoapEnumAttribute();
soapEnum.set_Name("East");
SoapAtts.set_SoapEnum(soapEnum);
soapOver.Add(GroupType.class.ToType(), "B", SoapAtts);
Group myGroup = new Group();
myGroup.groupName = ".NET";
myGroup.groupType = new GroupType(GroupType.B);
TextWriter writer = new StreamWriter(fileName);

// HERE_____________________
XmlSerializer ser = new XmlSerializer( myGroup.GetType() );
// __________________________

ser.Serialize(writer, myGroup);
writer.Close();
} //SerializeOverride

} //Run



Regards,
Lars-Inge Tnessen
www.larsinge.com
 
 
 

InvalidOperationException was unhandled

Post by diganta.vj » Tue, 07 Sep 2004 15:19:44

emember to change
/** @attribute SoapAttribute(Namespace = http://www.cpandl.com) */
to
/** @attribute SoapAttribute(Namespace = "http://www.cpandl.com") */
in the repro code mentioned below.

Thanks,
Diganta Roy
Microsoft Visual J# .NET Product Team

This posting is provided "AS IS" with no warranties, and confers no
rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm

-------------------
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11
.phx.gbl