Note that there are some explanatory texts on larger screens.

plurals
  1. POXml serialization and empty file
    primarykey
    data
    text
    <p>I stomped on some very weird bug which is very hard to reproduce I literally cant reproduce it. We have a window service installed on around 300+ PCs. From time to time config file(xml) that is used by this service become clear (on some of them). Totally clear no xml tags, nothing, 0kb. I have no clue what can cause such problem. No exception is logged in our logs. Even after this config becoming clear it's still running however it's not communicating with our web service. This is the class that is used for xml serialization and deserialization. I can’t find what can be possibly causing such behavior. Of course problem might not be in this particular class. Any suggestions?? Maybe some hints what can cause a file to become clear. When any operation on this file is by using this class.</p> <p>Sorry for my bad English.</p> <pre><code>[XmlRootAttribute("xmlconfig", Namespace = "DSD_Config", IsNullable = false)] public class xmlconfig { [XmlElementAttribute(IsNullable = false)] public string ProgramApteczny { get; set; } public string Server { get; set; } public string Database { get; set; } public string User { get; set; } public string Password { get; set; } public string DSDUser { get; set; } public string DSDPassword { get; set; } public string DSDServerAdres { get; set; } //public static string cofFile = System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\DSD_Agent\\config.xml"; public static string cofFile = Application.StartupPath + "\\config.xml"; public xmlconfig() { } public xmlconfig(string sProgramApteczny, string sServer, string sDatabase, string sUser, string sPassword, string sDSDUser, string sDSDPassword, string sDSDServerAdres) { ProgramApteczny = sProgramApteczny; Server = sServer; Database = sDatabase; User = sUser; Password = sPassword; DSDUser = sDSDUser; DSDPassword = sDSDPassword; DSDServerAdres = sDSDServerAdres; } public static void readXMLConfig(out xmlconfig configFile) { XmlSerializer oSerializer = new XmlSerializer(typeof(xmlconfig)); configFile = new xmlconfig(); try { using (FileStream fs = new FileStream(cofFile, FileMode.Open, FileAccess.Read)) { configFile = (xmlconfig)oSerializer.Deserialize(fs); try { configFile.Password = Encryption.DecryptString(configFile.Password); } catch (Exception) { configFile.Password = configFile.Password; } try { configFile.DSDPassword = Encryption.DecryptString(configFile.DSDPassword); } catch (Exception) { configFile.DSDPassword = configFile.DSDPassword; } } } catch { configFile = null; } } public static void writeXMLConfig(string sProgramApteczny, string sServer, string sDatabase, string sUser, string sPassword, string sDSDUser, string sDSDPassword) { xmlconfig oxmlconfig = new xmlconfig(); readXMLConfig(out oxmlconfig); sPassword = Encryption.EncryptString(sPassword); sDSDPassword = Encryption.EncryptString(sDSDPassword); if (oxmlconfig == null) { oxmlconfig = new xmlconfig(sProgramApteczny, sServer, sDatabase, sUser, sPassword, sDSDUser, sDSDPassword, ""); } else { oxmlconfig.ProgramApteczny = sProgramApteczny; oxmlconfig.Server = sServer; oxmlconfig.Database = sDatabase; oxmlconfig.User = sUser; oxmlconfig.Password = sPassword; oxmlconfig.DSDUser = sDSDUser; oxmlconfig.DSDPassword = sDSDPassword; } XmlSerializer oSerializer = new XmlSerializer(typeof(xmlconfig)); TextWriter oStreamWriter = null; try { oStreamWriter = new StreamWriter(cofFile, false); oSerializer.Serialize(oStreamWriter, oxmlconfig); } catch (Exception oException) { WriteToLog(DateTime.Now, "Aplikacja wygenerowała następujący wyjątek: " + oException.Message); // Console.WriteLine("Aplikacja wygenerowała następujący wyjątek: " + oException.Message); } finally { if (null != oStreamWriter) { oStreamWriter.Close(); } } } public static void writeXMLDSDConfig(string sDSDServerAdres) { xmlconfig oxmlconfig = new xmlconfig(); readXMLConfig(out oxmlconfig); if (oxmlconfig == null) { throw new Exception("Aplikacja wygenerowała następujący wyjątek: Musisz zdefiniować wszystkie parametry"); } else { oxmlconfig.DSDPassword = Encryption.EncryptString(oxmlconfig.DSDPassword); oxmlconfig.Password = Encryption.EncryptString(oxmlconfig.Password); oxmlconfig.DSDServerAdres = sDSDServerAdres; } XmlSerializer oSerializer = new XmlSerializer(typeof(xmlconfig)); TextWriter oStreamWriter = null; try { oStreamWriter = new StreamWriter(cofFile, false); oSerializer.Serialize(oStreamWriter, oxmlconfig); } catch (Exception oException) { throw new Exception("Aplikacja wygenerowała następujący wyjątek: " + oException.Message); } finally { if (null != oStreamWriter) { oStreamWriter.Close(); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload