title: Why can I only write ONE item in my Resource.resx file?
body: <p>I thought I am writing 10 file extensions and their related Icons as Bitmap into a resource file within a for loop. The odd thing is that only the last file extension with its Icon is written into the Resource.resx file. Somehow the next file extension in the loop is overwriting the previous one, but WHY ? I thought a resource is sort of a dictionary with key/value pair where I can add as much as I want just as I do in the Resource designer...</p>
  
  <p>What do I wrong?</p>
  
  <p>My code:</p>
  
  <pre><code>private void AddDocument()
          {
              OpenFileDialog fileDialog = new OpenFileDialog();
              fileDialog.Multiselect = true;
  
              DialogResult result = fileDialog.ShowDialog();
              if (result == DialogResult.OK)
              {
                  for (int i = 0; i &lt; fileDialog.FileNames.Length; i++)
                  {
                      string absoluteFilePath = fileDialog.FileNames.GetValue(i).ToString();
                      byte[] file = File.ReadAllBytes(absoluteFilePath);
                      String fileExtension = Path.GetExtension(absoluteFilePath);
  
                      Bitmap gdiImage;
  
                      Document doc = new Document();
                      doc.DocumentData = file;
                      doc.DocumentName = fileDialog.SafeFileNames.GetValue(i).ToString();
  
  
                      if (TryIsFileExtensionExisting(fileExtension, out gdiImage))
                      {
                          // Filetype was saved before =&gt; Convert GDI Bitmap to wpf BitmapImage
                          doc.DocumentTypeImage = gdiImage.ConvertGDIImageToWPFBitmapImage();
                      }
                      else
                      {
                          BitmapImage wpfImage;
                          // Filetype is new =&gt; get Bitmap out of the Icon
                          Icon icon = IconFromFilePath(absoluteFilePath);
                          Bitmap bitmap = icon.ToBitmap();
                          wpfImage = bitmap.ConvertGDIImageToWPFBitmapImage();
                          doc.DocumentTypeImage = wpfImage;
  
                          // Save bitmap to resource
                          using (ResXResourceWriter writer = new ResXResourceWriter("TBM.Resource"))
                          {
                              writer.AddResource(fileExtension, bitmap);
                              writer.Generate();
                          }
                      }                    
  
                      DocumentList.Add(doc);
                  }
                  _documentService.AddDocumentsToPeriod(DocumentList, _parentId);
              }
          }
  
          private bool TryIsFileExtensionExisting(String fileExtension, out Bitmap wpfImage)
          {
              DictionaryEntry entry;
              using (ResXResourceReader reader = new ResXResourceReader ("TBM.Resource"))
              {
                  entry = reader.Cast&lt;DictionaryEntry&gt;()
                                          .Where(x =&gt; x.Key.ToString()
                                          .Equals(fileExtension, StringComparison.CurrentCultureIgnoreCase))
                                          .FirstOrDefault();
              };            
  
              wpfImage = entry.Value as Bitmap;
              return entry.Key != null; 
          }
  
          private Icon IconFromFilePath(string filePath)
          {
              Icon result = null;
              try
              {
                  result = Icon.ExtractAssociatedIcon(filePath);
                  //'# swallow and return nothing. You could supply a default Icon here as well
              }
              catch
              {
              }
              return result;
          }
  </code></pre>