Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After poking around some more (i.e. googling the answer), I was able to resolve this. Here is the modified code:</p> <p>Interfaces.cs (from a referenced assembly, Interfaces.dll)</p> <pre><code>public interface ISomeInterface { ISettings Settings { get; set; } } public interface ISettings { DateTime StartDate { get; } } </code></pre> <p>SomeClass.cs (from a referenced assembly, SomeClass.dll)</p> <pre><code>public class SomeClass : ISomeInterface { private MySettings settings = new Settings(); public ISettings Settings { get { return (ISettings)settings; } set { settings = value as MySettings; } } } [Serializable] public class MySettings : ISettings { private DateTime dt; public MySettings() { dt = DateTime.Now; } public DateTime StartDate { get { return startFrom; } internal set { startFrom = value; } } } </code></pre> <p>Serialization is done with:</p> <pre><code>public void SerializeState(string filename, ProgramState ps) { Stream s = File.Open(filename, FileMode.Create); BinaryFormatter bFormatter = new BinaryFormatter(); bFormatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple; bFormatter.Serialize(s, ps); s.Close(); } </code></pre> <p>And deserialization with:</p> <pre><code>public ProgramState DeserializeState(string filename) { if (File.Exists(filename)) { ProgramState res = new ProgramState(); Stream s = File.Open(filename, FileMode.Open); BinaryFormatter bFormatter = new BinaryFormatter(); bFormatter.AssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple; bFormatter.Binder = new MyBinder(); // MyBinder class code given below try { res = (ProgramState)bFormatter.Deserialize(s); } catch (SerializationException se) { Debug.WriteLine(se.Message); } s.Close(); return res; } else return new ProgramState(); } </code></pre> <p>This class was added. This is the binder for the binary formatter:</p> <pre><code>internal sealed class MyBinder : SerializationBinder { public override Type BindToType(string assemblyName, string typeName) { Type ttd = null; try { string toassname = assemblyName.Split(',')[0]; Assembly[] asmblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly ass in asmblies) { if (ass.FullName.Split(',')[0] == toassname) { ttd = ass.GetType(typeName); break; } } } catch (System.Exception e) { Debug.WriteLine(e.Message); } return ttd; } } </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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