HighTechTalks DotNet Forums  

InvalidOperationException was unhandled

Dotnet VJSharp microsoft.public.dotnet.vjsharp


Discuss InvalidOperationException was unhandled in the Dotnet VJSharp forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Prasad Godde
 
Posts: n/a

Default InvalidOperationException was unhandled - 05-12-2004 , 12:31 AM






I 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 overRideSerializer = CreateOverrideSerializer()
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
overRideSerializer.Serialize(writer, myGroup)
writer.WriteEndElement()
writer.Close()
} //SerializeOverrid

private Group MakeGroup(

// Create an instance of the class that will be serialized
Group myGroup = new Group()
// Set the object properties.
myGroup.GroupName = ".NET";

System.Byte hexByte[] = new System.Byte[] { (System.Byte)100, (System.Byte)50 };
myGroup.GroupNumber = hexByte;

DateTime myDate = new DateTime(2002, 5, 2);
myGroup.Today = myDate;
myGroup.PostitiveInt = "10000";
myGroup.IgnoreThis = true;
myGroup.Grouptype = new GroupType(GroupType.B);
Car thisCar = ( Car)myGroup.myCar("1234566");
myGroup.MyVehicle = thisCar;
return myGroup;
} //MakeGroup

public void DeserializeOriginal(String filename)
{
// Create an instance of the XmlSerializer class.
XmlTypeMapping myMapping = (new SoapReflectionImporter()).ImportTypeMapping(Group. class.ToType());
XmlSerializer mySerializer = new XmlSerializer(myMapping);
// Reading the file requires an XmlTextReader.
XmlTextReader reader = new XmlTextReader(filename);
reader.ReadStartElement("wrapper");
// Deserialize and cast the object.
Group myGroup;
myGroup = ((Group)(mySerializer.Deserialize(reader)));
reader.ReadEndElement();
reader.Close();
} //DeserializeOriginal

public void DeserializeOverride(String filename)
{
// Create an instance of the XmlSerializer class.
XmlSerializer overRideSerializer = CreateOverrideSerializer();
// Reading the file requires an XmlTextReader.
XmlTextReader reader = new XmlTextReader(filename);
reader.ReadStartElement("wrapper");
// Deserialize and cast the object.
Group myGroup;
myGroup = ((Group)(overRideSerializer.Deserialize(reader)));
reader.ReadEndElement();
reader.Close();
ReadGroup(myGroup);
} //DeserializeOverride

private void ReadGroup(Group myGroup)
{
Console.WriteLine(myGroup.GroupName);
Console.WriteLine(myGroup.GroupNumber.get_Item(0)) ;
Console.WriteLine(myGroup.GroupNumber.get_Item(1)) ;
Console.WriteLine(myGroup.Today);
Console.WriteLine(myGroup.PostitiveInt);
Console.WriteLine(myGroup.IgnoreThis);
Console.WriteLine();
} //ReadGroup

private XmlSerializer CreateOverrideSerializer()
{
SoapAttributeOverrides mySoapAttributeOverrides = new SoapAttributeOverrides();
SoapAttributes soapAtts = new SoapAttributes();

SoapElementAttribute mySoapElement = new SoapElementAttribute();
mySoapElement.set_ElementName("xxxx");
soapAtts.set_SoapElement(mySoapElement);
mySoapAttributeOverrides.Add(Group.class.ToType(), "PostitiveInt", soapAtts);
// Override the IgnoreThis property.
SoapIgnoreAttribute myIgnore = new SoapIgnoreAttribute();
soapAtts = new SoapAttributes();
soapAtts.set_SoapIgnore(false);
mySoapAttributeOverrides.Add(Group.class.ToType(), "IgnoreThis", soapAtts);
// Override the GroupType enumeration.
soapAtts = new SoapAttributes();
SoapEnumAttribute xSoapEnum = new SoapEnumAttribute();
xSoapEnum.set_Name("Over1000");
soapAtts.set_SoapEnum(xSoapEnum);
// Add the SoapAttributes to the
// mySoapAttributeOverridesrides object.
mySoapAttributeOverrides.Add(GroupType.class.ToTyp e(), "A", soapAtts);
// Create second enumeration and add it.
soapAtts = new SoapAttributes();
xSoapEnum = new SoapEnumAttribute();
xSoapEnum.set_Name("ZeroTo1000");
soapAtts.set_SoapEnum(xSoapEnum);
mySoapAttributeOverrides.Add(GroupType.class.ToTyp e(), "B", soapAtts);
// Override the Group type.
soapAtts = new SoapAttributes();
SoapTypeAttribute soapType = new SoapTypeAttribute();
soapType.set_TypeName("Team");
soapAtts.set_SoapType(soapType);
mySoapAttributeOverrides.Add(Group.class.ToType(), soapAtts);
// Create an XmlTypeMapping that is used to create an instance
// of the XmlSerializer. Then return the XmlSerializer object.
XmlTypeMapping myMapping = (new SoapReflectionImporter(mySoapAttributeOverrides)). ImportTypeMapping(Group.class.ToType());

XmlSerializer ser = new XmlSerializer(myMapping);
return ser;
} //CreateOverrideSerializer
} //Run
//</Snippet1>

Reply With Quote
  #2  
Old   
AT
 
Posts: n/a

Default Re: InvalidOperationException was unhandled - 09-06-2004 , 02:19 AM






Remember 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

-------------------
Quote:
Reply-To: "Lars-Inge Tønnessen" <http://emailme.larsinge.com
From: "Lars-Inge Tønnessen" <http://emailme.larsinge.com
References: <7BA3C100-4F75-413C-B402-9EB94041BF5B (AT) microsoft (DOT) com
Subject: Re: InvalidOperationException was unhandled
Date: Thu, 13 May 2004 23:08:19 +0200
Lines: 255
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
Message-ID: <u0rD45SOEHA.3028 (AT) TK2MSFTNGP11 (DOT) phx.gbl
Newsgroups: microsoft.public.dotnet.vjsharp
NNTP-Posting-Host: ans-118.vpn.uit.no 129.242.154.123
Path:
cpmsftngxa10.phx.gbl!TK2MSFTFEED01.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP11
.phx.gbl
Quote:
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.vjsharp:6032
X-Tomcat-NG: microsoft.public.dotnet.vjsharp

Now 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 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.
overRideSerializer.Serialize(writer, myGroup);
writer.WriteEndElement();
writer.Close();
} //SerializeOverride

private Group MakeGroup()
{
// Create an instance of the class that will be serialized.
Group myGroup = new Group();
// Set the object properties.
myGroup.GroupName = ".NET";
System.Byte hexByte[] = new System.Byte[] { (System.Byte)100,
(System.Byte)50 };
myGroup.GroupNumber = hexByte;
DateTime myDate = new DateTime(2002, 5, 2);
myGroup.Today = myDate;
myGroup.PostitiveInt = "10000";
myGroup.IgnoreThis = true;
myGroup.Grouptype = new GroupType(GroupType.B);
Car thisCar = ( Car)myGroup.myCar("1234566");
myGroup.MyVehicle = thisCar;
return myGroup;
} //MakeGroup

public void DeserializeOriginal(String filename)
{
// Create an instance of the XmlSerializer class.
XmlTypeMapping myMapping = (new
SoapReflectionImporter()).ImportTypeMapping(Group. class.ToType());
XmlSerializer mySerializer = new XmlSerializer(myMapping);
// Reading the file requires an XmlTextReader.
XmlTextReader reader = new XmlTextReader(filename);
reader.ReadStartElement("wrapper");
// Deserialize and cast the object.
Group myGroup;
myGroup = ((Group)(mySerializer.Deserialize(reader)));
reader.ReadEndElement();
reader.Close();
} //DeserializeOriginal

public void DeserializeOverride(String filename)
{
// Create an instance of the XmlSerializer class.
XmlSerializer overRideSerializer = CreateOverrideSerializer();
// Reading the file requires an XmlTextReader.
XmlTextReader reader = new XmlTextReader(filename);
reader.ReadStartElement("wrapper");
// Deserialize and cast the object.
Group myGroup;
myGroup = ((Group)(overRideSerializer.Deserialize(reader)));
reader.ReadEndElement();
reader.Close();
ReadGroup(myGroup);
} //DeserializeOverride

private void ReadGroup(Group myGroup)
{
Console.WriteLine(myGroup.GroupName);
Console.WriteLine(myGroup.GroupNumber.get_Item(0)) ;
Console.WriteLine(myGroup.GroupNumber.get_Item(1)) ;
Console.WriteLine(myGroup.Today);
Console.WriteLine(myGroup.PostitiveInt);
Console.WriteLine(myGroup.IgnoreThis);
Console.WriteLine();
} //ReadGroup

private XmlSerializer CreateOverrideSerializer()
{
SoapAttributeOverrides mySoapAttributeOverrides = new
SoapAttributeOverrides();
SoapAttributes soapAtts = new SoapAttributes();
SoapElementAttribute mySoapElement = new SoapElementAttribute();
mySoapElement.set_ElementName("xxxx");
soapAtts.set_SoapElement(mySoapElement);
mySoapAttributeOverrides.Add(Group.class.ToType(), "PostitiveInt",
soapAtts);
// Override the IgnoreThis property.
SoapIgnoreAttribute myIgnore = new SoapIgnoreAttribute();
soapAtts = new SoapAttributes();
soapAtts.set_SoapIgnore(false);
mySoapAttributeOverrides.Add(Group.class.ToType(), "IgnoreThis",
soapAtts);
// Override the GroupType enumeration.
soapAtts = new SoapAttributes();
SoapEnumAttribute xSoapEnum = new SoapEnumAttribute();
xSoapEnum.set_Name("Over1000");
soapAtts.set_SoapEnum(xSoapEnum);
// Add the SoapAttributes to the
// mySoapAttributeOverridesrides object.
mySoapAttributeOverrides.Add(GroupType.class.ToTyp e(), "A",
soapAtts);
// Create second enumeration and add it.
soapAtts = new SoapAttributes();
xSoapEnum = new SoapEnumAttribute();
xSoapEnum.set_Name("ZeroTo1000");
soapAtts.set_SoapEnum(xSoapEnum);
mySoapAttributeOverrides.Add(GroupType.class.ToTyp e(), "B",
soapAtts);
// Override the Group type.
soapAtts = new SoapAttributes();
SoapTypeAttribute soapType = new SoapTypeAttribute();
soapType.set_TypeName("Team");
soapAtts.set_SoapType(soapType);
mySoapAttributeOverrides.Add(Group.class.ToType(), soapAtts);
// Create an XmlTypeMapping that is used to create an instance
// of the XmlSerializer. Then return the XmlSerializer object.
XmlTypeMapping myMapping = (new SoapReflectionImporter
(mySoapAttributeOverrides)).ImportTypeMapping(Grou p.class.ToType());
XmlSerializer ser = new XmlSerializer(myMapping);
return ser;
} //CreateOverrideSerializer
} //Run



Regards,
Lars-Inge Tønnessen
www.larsinge.com





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.