title: Image format Unknown
body: <p>I am trying to read an image into Base64 format using .Net Core 2.2 and it throws</p>
  
  <blockquote>
    <p>ArgumentException: Image format is unknown.
    System.Drawing.Image.FromFile(string filename, bool useEmbeddedColorManagement)</p>
  </blockquote>
  
  <p>The filePath is correct, and I have double and triple checked that the file exists.</p>
  
  <p>I have attempted naming my PNGs with both upper and lowercase extension.</p>
  
  <p>This does not happen locally on windows, but once the application is deployed to linux is happens.  The code in question is below.</p>
  
  <pre><code>    public static string ImageToBase64(string filePath)
      {
          System.Diagnostics.Debug.WriteLine($"File Path for Image: {filePath}");
          string base64String;
          using (var image = Image.FromFile(Path.GetFullPath(filePath)))
          {
              using (var ms = new MemoryStream())
              {
                  image.Save(ms, image.RawFormat);
                  image.Dispose();
                  byte[] imageBytes = ms.ToArray();
                  base64String = Convert.ToBase64String(imageBytes);
                  imageBytes = null;
                  ms.Dispose();
              }
          }
          GC.Collect();
          return base64String;
      }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>I also tried using a filestream with bitmap.</p>
  
  <pre><code>    public static string ImageToBase64(string filePath)
      {
          string base64String;
          using(var fs = new FileStream(filePath,FileMode.Open))
          using (var image = new Bitmap(fs))
          {
              using (var ms = new MemoryStream())
              {
                  image.Save(ms, ImageFormat.Png);
                  image.Dispose();
                  byte[] imageBytes = ms.ToArray();
                  base64String = Convert.ToBase64String(imageBytes);
                  imageBytes = null;
                  ms.Dispose();
              }
          }
          GC.Collect();
          return base64String;
      }
  </code></pre>
  
  <p>This throws the following exception:</p>
  
  <blockquote>
    <p>Exception thrown: 'System.ArgumentException' in
    System.Drawing.Common.dll: 'Image format is unknown.' Stack trace:</p>
    
    <blockquote>
      <p>at System.Drawing.Image.InitializeFromStream(Stream stream)
        at System.Drawing.Bitmap..ctor(Stream stream)</p>
    </blockquote>
  </blockquote>