我是 WPF 應用程式編程的新手。我嘗試創建一個可以打開對話框的按鈕,在選擇 .exe 檔案后,我可以提取該檔案的圖示。
我從“專案 - > 管理 NuGet 包”安裝 System.Drawing.Common 依賴項版本 7.0.0。
我在帶有 .NETCore 版本 3.1 的 Windows 10 上使用 VS studio 2019。
當我運行我的程式時,它會彈出錯誤“System.PlatformNotSupportedException: 'System.Drawing.Common is not supported on this platform.'”。
這是代碼
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
}
}
希望我解釋清楚,并感謝您的幫助。
我嘗試在 app.runtimeconfig.json 中添加此代碼,但無法正常作業。
"configProperties": {
"System.Drawing.EnableUnixSupport": true
}
uj5u.com熱心網友回復:
我有同樣的問題,我將包降級到版本 6.0.0.0 并且錯誤消失了
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/532978.html
標籤:C#wpf
上一篇:從物件函式更新背景關系
