I have 2 views (console and wpf) and 1 dll with program logic. In 1 wpf I want to set some user settings and then use them in console even after the wpf is closed. But the settings always reset after closing the wpf. I am trying to save a list of objects, so that's why the code is also using MemoryStream, BinaryFormatter, etc. but I think it makes no difference in the functionality of the ConfigurationManager.
This is example of my code:
public List<CsprojFile> FilesArray
{
get
{
try
{
using (
MemoryStream memoryStreams =
new MemoryStream(Convert.FromBase64String(ConfigurationManager.AppSettings["filesArray"])))
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
return (List<CsprojFile>) binaryFormatter.Deserialize(memoryStreams);
}
}
catch
{
return new List<CsprojFile>();
}
}
set
{
using (MemoryStream memoryStream = new MemoryStream())
{
BinaryFormatter binaryFormatter = new BinaryFormatter();
binaryFormatter.Serialize(memoryStream, value);
memoryStream.Position = 0;
byte[] buffer = new byte[(int)memoryStream.Length];
memoryStream.Read(buffer, 0, buffer.Length);
ConfigurationManager.AppSettings["filesArray"] = Convert.ToBase64String(buffer);
}
}
}