Sparx Systems Forum
Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: jafuentes on October 26, 2010, 02:50:33 am
-
Hello,
I´ve following problem. I´ve a model that i need to serialize. I´m using EA8 and VS2010/C#. In an Addin, i call the method SerializeObject:
private String UTF8ByteArrayToString(Byte[] characters)
{
UTF8Encoding encoding = new UTF8Encoding();
String constructedString = encoding.GetString(characters);
return (constructedString);
}
private Byte[] StringToUTF8ByteArray(String pXmlString)
{
UTF8Encoding encoding = new UTF8Encoding();
Byte[] byteArray = encoding.GetBytes(pXmlString);
return byteArray;
}
public String SerializeObject(Repository rep)
{
try{
String XmlizedString = null;
MemoryStream memoryStream = new MemoryStream();
XmlSerializer xs = new XmlSerializer(typeof(rep.GetType()));
XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
xs.Serialize(xmlTextWriter, rep);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
return XmlizedString;
}
catch (Exception e){
System.Console.WriteLine(e);
return null;
}
}
when executed this line:
XmlSerializer xs = new XmlSerializer(rep.GetType());
And exception ocurrs. The error is:
$exception {"Unable to generate a temporary class (result=1).\r\nerror CS0122: 'System.__ComObject' is inaccessible due to its protection level\r\nerror CS0051: Inconsistent accessibility: parameter type 'System.__ComObject' is less accessible than method 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter__ComObject.Write3___ComObject(string, string, System.__ComObject, bool, bool)'\r\nerror CS0122: 'System.__ComObject' is inaccessible due to its protection level\r\nerror CS0050: Inconsistent accessibility: return type 'System.__ComObject' is less accessible than method 'Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReader__ComObject.Read3___ComObject(bool, bool)'\r\n"} System.Exception {System.InvalidOperationException}
How I can serialize rep?
Thanks. Regards
-
EA automation objects don't support serialization.
What you probably want is to export to xmi. (Which is available from the project interface from memory.)