title: Reflection | Emit | Dynamic Resource Generation - Added resource values using IResourceWriter.AddResource(key,value) cannot read
body: <p>I am trying to generate an assembly file with some resources. I am using <code>System.Reflection.Emit.ModuleBuilder</code> to define resources. <code>AssemblyBuilder</code> save assembly without giving any errors but when I am trying read resources, <code>ResourceManager</code> doesn't have any entry in it's <code>ResourceSets</code>. I am not sure <code>AssemblyBuilder</code> doesn't save added resources or my resource reading code has issues. </p>
  
  <p>Assembly generation code:</p>
  
  <pre><code>public void GenerateAsm()
      {
          string myAsmName = "MyAssembly.resources";
          string myAsmFileName = myAsmName + ".dll";
          string resourceName = "MyAssembly.Resource.fr.resources";
  
          AppDomain appDomain = Thread.GetDomain();
          AssemblyName asmName = new AssemblyName();
          asmName.Name = myAsmName;
          AssemblyBuilder myAsmBuilder = appDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.RunAndSave);
  
          ModuleBuilder myModuleBuilder = myAsmBuilder.DefineDynamicModule(myAsmFileName,myAsmFileName);
          IResourceWriter rw = myModuleBuilder.DefineResource(resourceName, "My Description", ResourceAttributes.Public);
  
          rw.AddResource("ResKey1", "Resource value 1.");
          rw.AddResource("ResKey2", "Resource value 2.");
          myAsmBuilder.Save(myAsmFileName);    
      }
  </code></pre>
  
  <p>Resource reading code:</p>
  
  <pre><code>public void ReadResource()
      {
          ResourceManager rm = new ResourceManager("MyAssembly.Resource.fr.resources", Assembly.LoadFrom("MyAssembly.resources.dll"));
          string greeting = rm.GetString("ResKey1");
      }
  </code></pre>
  
  <p>Resource manager can load resource but it doesn't have any key value pairs.</p>