How do I create and recall class objects from a resource file that I can use at runtime?
<p>I am trying to create a resource file of message codes.  I've created a small console example that fails when I try to recall the object.</p>

<p>I based this on this <a href="https://msdn.microsoft.com/en-us/library/xbx3z216(v=vs.100).aspx" rel="nofollow">MSDN -Creating Resource Files</a> example, but I don't know what I've missed while I tried to simplify it.</p>

<p>In the code I run it once to generate the resource file and add that file to the project. Then I recompile to run the recall code.</p>

<pre><code>using System;
using System.Reflection;
using System.Resources;

namespace ResourceDemo
{
  internal class Program
  {
    private static void Main(string[] args)
    {
      bool generateMode = false;

      if (generateMode) {
        // After running once with generate mode set to true, add the resulting
        // "StatusItem.resource" that was created in the .\bin\x86\Debug folder
        // to the project.
        Generate();
      }
      else {
        // When run the next line generates an exception:
        //   An unhandled exception of type 'System.Resources.MissingManifestResourceException' occurred in mscorlib.dll
        //
        //   Additional information: Could not find any resources appropriate for the specified culture
        //   or the neutral culture.  Make sure "StatusItems.resources" was correctly embedded or linked
        //   into assembly "ResourceDemo" at compile time, or that all the satellite assemblies required
        //   are loadable and fully signed.

        StatusItem statusItem = GetResource("2");
        Console.WriteLine("Id: {0}  Message: {1}", statusItem.Id.ToString(), statusItem.Message);
        Console.ReadKey();
      }
    }

    public static void Generate()
    {
      StatusItem[] statusItem = new StatusItem[4];

      // Instantiate an Status object items.
      statusItem[0] = new StatusItem(2, "File not found");
      statusItem[1] = new StatusItem(3, "Path not found");
      statusItem[2] = new StatusItem(4, "Too many open files");
      statusItem[3] = new StatusItem(5, "File access denied");

      // Define a resource file named StatusItems.resx.
      using (System.Resources.ResourceWriter rw = new ResourceWriter(@".\StatusItems.resources")) {
        for (int i = 0; i &lt; 4; i++) {
          rw.AddResource(statusItem[i].Id.ToString(), statusItem[i]);
        }

        rw.Generate();
      }
    }

    public static StatusItem GetResource(string key)
    {
      Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
      System.Resources.ResourceManager rm = new System.Resources.ResourceManager("StatusItems", Assembly.Load("ResourceDemo"));

      return (StatusItem)rm.GetObject(key);
    }

    [Serializable()]
    public class StatusItem
    {
      public StatusItem(int id, string message)
      {
        Id = id;
        Message = message;
      }

      public int Id { get; set; }
      public string Message { get; set; }
    }
  }
}
</code></pre>