writer.AddResource("Story", xml);
That does not do what you hope it does. There is a lot more to embedding resources than meets the eye. Lots of work done by the IDE and msbuild.exe to make the Properties.Resources code work at runtime. The rough steps:
- Project + Properties, Resource tab, Add Resource generates an .xml file. Presumably one that's very similar to the one you are using in your code.
- That also auto-generates code, you can see it by opening the Properties + Resources.resx + Resources.Designer.cs file. It is this file that declares the Properties.Resources class. This step is not being done in your code which explains the compile error
- At build time, the .resx file is translated from XML to a format that's more compact and suitable to be embedded inside an assembly. This is done by the Resgen.exe build tool. It translates from the .xml file to a .resources file. Note how you got that wrong as well, you are writing the xml to the .resources file instead of the Resgen.exe output.
Reproducing all this with CodeDom does get to be quite painful, particularly the auto-generated code step. Practical approaches are keeping the resources in files instead of trying to embed them, embedding a single resource and retrieving at runtime with Assembly.GetManifestResourceStream() and using ResourceManager explicitly as shown in the Resources.Designer.cs file.