title: Custom Object in Resource File
body: <p>Based on <a href="http://www.codeproject.com/Articles/10235/Type-converters-your-friendly-helpers" rel="nofollow">a TypeConverter article for making custom resource objects</a>, the following code is working correctly:</p>
  
  <pre><code>string file = @".\SomeResources.resx";
  using (ResXResourceWriter resx = new ResXResourceWriter(file))
  {
      resx.AddResource("test", "me");
      resx.AddResource("when", DateTime.Now);
      resx.AddResource("custom", new LogPair { Key = "check", Value = "clear" });
  }
  using (ResXResourceSet resxSet = new ResXResourceSet(file))
  {
      var check = (LogPair)resxSet.GetObject("custom", true);
  }
  </code></pre>
  
  <p>Most notably, I am successfully retrieving the custom <code>LogPair</code> object instance.</p>
  
  <p>I then use resgen to compile the resx into a resource file, and then execute this code:</p>
  
  <pre><code>var stuff = ResourceManager.CreateFileBasedResourceManager("SomeResources", ".", null);
  string res = stuff.GetString("test");
  var info = (LogPair)stuff.GetObject("custom");
  var now = (DateTime)stuff.GetObject("when");
  </code></pre>
  
  <p>The string <code>res</code> is fetched correctly, giving the value of "me".  The <code>DateTime</code> is also fetched correctly.  However, the <code>info</code> variable is set to null.  So then I use Visual Studio to peek at the resource file that resgen generated.  It shows that my custom object was converted to a null type (hex value of zero).</p>
  
  <p>So the issue appears to be in resgen itself.  I also learned that the issue is related to my custom TypeConverter.  My custom TypeConverter is used to (de-)serialize my <code>LogPair</code> as JSON.  Notice the resx file below:</p>
  
  <pre><code>  &lt;data name="test" xml:space="preserve"&gt;
      &lt;value&gt;me&lt;/value&gt;
    &lt;/data&gt;
    &lt;assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /&gt;
    &lt;data name="when" type="System.DateTime, mscorlib"&gt;
      &lt;value&gt;07/30/2014 13:23:59&lt;/value&gt;
    &lt;/data&gt;
    &lt;assembly alias="Serve.Shared.Apis.Injection.Test" name="Serve.Shared.Apis.Injection.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /&gt;
    &lt;data name="custom" type="Injection.Test.LogPair, Serve.Shared.Apis.Injection.Test"&gt;
      &lt;value&gt;{"Key":"check","Value":"clear"}&lt;/value&gt;
    &lt;/data&gt;
  </code></pre>
  
  <p>Again, I can read the above resx succuessfully.  There is only a problem when I use resgen to compile it to a resource file.  I used this command:</p>
  
  <pre><code>Resgen /r:Serve.MyAssemblyName.dll SomeResources.resx
  </code></pre>
  
  <p>No errors are reported by resgen.</p>
  
  <p>If I abandon my custom TypeConverter, and allow resgen to use standard binary serialization (and a CDATA seciton, etc., etc.) then everything works fine.</p>
  
  <p>In short, resgen does not like my custom TypeConverter - even though resource files are designed to work with custom TypeConverters.</p>
  
  <p>How do I fix this?</p>