I have this C# code but I get the error in the title. on the "FromFile" part. I want to simply publish images in my PC on a WPF application.
How can I get rid of this error?

Code :

using System.Drawing;

namespace Photo
   public partial class MainWindow : Window
        public MainWindow()

            string filename1 = @"C:\images\mainicon.jpg";
            Image image1 = Image.FromFile(filename1);

Error :

'System.Windows.Controls.Image' does not contain a definition for 'FromFile'

It looks like the compiler is interpreting Image as System.Windows.Controls.Image rather than System.Drawing.Image. The error is correct in that the target class doesn't have a FromFile method.

I'm a bit surprised that you're not getting an ambiguity error instead, but a quick fix would be to fully qualify the class:

var image1 = System.Drawing.Image.FromFile(filename1);