Home > OS >  Using System.Drawing.Common in WPF in Win10 Shows not Support on Platform Error
Using System.Drawing.Common in WPF in Win10 Shows not Support on Platform Error

Time:11-10

I am new to the WPF application programming. I try to create a button that can open the dialog and after I select the .exe file, I can extract the icon of that file.

I install the System.Drawing.Common dependencies version 7.0.0 from "Project -> Manage NuGet Packages".

I am using the VS studio 2019 on Windows 10 with .NETCore Version 3.1.

When I run my program, it will popup the error "System.PlatformNotSupportedException: 'System.Drawing.Common is not supported on this platform.'".

Here is the code

using System.Drawing;

public string filePath { get; set; }

private void ChooseAppButton_Click(object sender, RoutedEventArgs e)
{
    OpenFileDialog fileDialog = new OpenFileDialog();
    fileDialog.Multiselect = true;
    fileDialog.Filter = "Execution Files|*.exe|All Files|*.*";
    fileDialog.DefaultExt = ".*";
    bool? dialogOpened = fileDialog.ShowDialog();

    if (dialogOpened == true)
    {
        filePath = fileDialog.FileName;
        appPathText.Text = filePath;
        Icon icon = System.Drawing.Icon.ExtractAssociatedIcon(filePath); //Error here
    }
}

Hope I explains clearly, and thanks for your help.

I tried to add this code in the app.runtimeconfig.json, but not working.

"configProperties": {
      "System.Drawing.EnableUnixSupport": true
}

CodePudding user response:

I had the same problem and I downgraded the package to version 6.0.0.0 and the error disappeared

  • Related