I'm trying to create an XML but it's causing the following error:
An exception of type 'System.InvalidOperationException' occurred in System.Xml.dll but was not handled in user code
Additional information: There was an error generating the XML document.
Code:
public Boolean GerarArquivoExportacaoOff(String caminhoArquivo)
{
Encoding iso_8859_1 = Encoding.GetEncoding("iso-8859-1");
StreamWriter streamWriter = new StreamWriter(caminhoArquivo, true, iso_8859_1, 100000);
List<OFFLINE_TABELAS> offline_TabelasList = getListaTabelasAlteradas(); // Seleciona tabelas alteradas
foreach (OFFLINE_TABELAS Entity_tabelas in offline_TabelasList)
{
var lista = getDados(Entity_tabelas.TABELA); // Obtem entidade a partir do nome da tabela
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(lista.GetType());
using (TextWriter textWriter = new StreamWriter("D:/usuarios.xml"))
{
//Definir o Type e o elemento raiz do XML (usuarios)
XmlSerializer ser = new XmlSerializer(lista.GetType(), new XmlRootAttribute("usuarios"));
//Serializar o list para o TextWriter e salvar os dados no XML
ser.Serialize(textWriter, lista);
}
}
return true
}
What's wrong with this?