all groups > vj# > may 2004 >
You're in the

vj#

group:

System.InvalidOperationException .Please help



System.InvalidOperationException .Please help Reshma
5/3/2004 3:06:01 AM
vj#: Hello
I am getting System.InvalidOperationException in the following line while trying to execute the J# file.
XmlSerializer ser = new XmlSerializer(Group2.class.ToType())
The error description says
There was an error reflecting type 'Group2'

The whole code is
import System.*
import System.Xml.Serialization.*
import System.IO.*
public class Group

// The XmlTextAttribute with type set to string informs the
// XmlSerializer that strings should be serialized as XML text
/** @attribute XmlText(String.class) *
/** @attribute XmlElement(int.class) *
/** @attribute XmlElement(double.class) *
public Object all[] = new Object[] { (Int32)321, "One", (Int32)2
(System.Double)3.0, "Two" }
}
public class Group

/** @attribute XmlText(Type = GroupType.class
*
public GroupType type
}
public class GroupTyp

private int member
public void setMember(int n

member = n

public static int small
public static int medium
public static int large
}
public class Group

/** @attribute XmlText(Type = DateTime.class) *
public DateTime creationTime = DateTime.get_Now()
}
public class Tes

public static void main(String[] args

Test t = new Test()
t.SerializeArray("XmlText1.xml")
t.SerializeEnum("XmlText2.xml")
t.SerializeDateTime("XmlText3.xml")
}
private void SerializeArray(String filename

XmlSerializer ser = new XmlSerializer(Group1.class.ToType())
Group1 myGroup1 = new Group1()
TextWriter writer = new StreamWriter(filename)
ser.Serialize(writer, myGroup1)
writer.Close()

private void SerializeEnum(String filename

XmlSerializer ser = new XmlSerializer(Group2.class.ToType())
Group2 myGroup = new Group2()
myGroup.type.setMember(GroupType.medium)
TextWriter writer = new StreamWriter(filename)
ser.Serialize(writer, myGroup)
writer.Close()

private void SerializeDateTime(String filename

XmlSerializer ser = new XmlSerializer(Group3.class.ToType())
Group3 myGroup = new Group3()
TextWriter writer = new StreamWriter(filename)
ser.Serialize(writer, myGroup)
writer.Close()

}

Thank

Re: System.InvalidOperationException .Please help Lars-Inge Tønnessen
5/6/2004 12:21:52 AM
Hello again. =:o)


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

public class Group1
{
// The XmlTextAttribute with type set to string informs the
// XmlSerializer that strings should be serialized as XML text.
/** @attribute XmlText(String.class) */
/** @attribute XmlElement(int.class) */
/** @attribute XmlElement(double.class) */
public Object all[] = new Object[]
{
(Int32)321, "One", (Int32)2,
(System.Double)3.0, "Two" };
}

public class Group2
{
// HERE______
/** @attribute XmlElement(GroupType.class, ElementName = "GroupType") */
public GroupType type = new GroupType();
// __________
}

public class GroupType
{
private int member;
public void setMember(int n)
{
member = n;
}

public static int small;
public static int medium;
public static int large;
}

public class Group3
{
// HERE_____
/** @attribute XmlElement(DateTime.class, ElementName = "DateTime") */
public DateTime creationTime = DateTime.get_Now();
// _________
}

public class Test
{
public static void main(String[] args)
{
Test t = new Test();
t.SerializeArray("XmlText1.xml");
t.SerializeEnum("XmlText2.xml");
t.SerializeDateTime("XmlText3.xml");
}

private void SerializeArray(String filename)
{
XmlSerializer ser = new XmlSerializer(Group1.class.ToType());
Group1 myGroup1 = new Group1();
TextWriter writer = new StreamWriter(filename);
ser.Serialize(writer, myGroup1);
writer.Close();
}

private void SerializeEnum(String filename)
{
XmlSerializer ser = new XmlSerializer(Group2.class.ToType());
Group2 myGroup = new Group2();
myGroup.type.setMember(GroupType.medium);
TextWriter writer = new StreamWriter(filename);
ser.Serialize(writer, myGroup);
writer.Close();
}

private void SerializeDateTime(String filename)
{
XmlSerializer ser = new XmlSerializer(Group3.class.ToType());
Group3 myGroup = new Group3();
TextWriter writer = new StreamWriter(filename);
ser.Serialize(writer, myGroup);
writer.Close();
}
}


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

AddThis Social Bookmark Button