简体   繁体   English

System.Drawing.Common 不适用于 Windows

[英]System.Drawing.Common not working on Windows

I'm trying to run a simple C# Application on windows 11. I'm using the System.Drawing to edit a png file, but this error is occuring.我正在尝试在 windows 11 上运行一个简单的 C# 应用程序。我正在使用 System.Drawing 编辑 png 文件,但出现了此错误。

System.PlatformNotSupportedException: 'System.Drawing.Common is not supported on this platform.' System.PlatformNotSupportedException:“此平台不支持 System.Drawing.Common。”

After a bit of research, turns out System.Drawing is only supported on windows.. but I am using windows.. Perhaps it's because I'm using windows 11?经过一番研究,原来 System.Drawing 仅在 windows 上受支持。但我使用的是 windows。可能是因为我使用的是 windows 11?

Furthermore, adding此外,添加

AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true);

Didn't seem to fix this issue either似乎也没有解决这个问题

The error is thrown on this line of code:在这行代码中抛出错误:

Bitmap bmp = new Bitmap(Bitmap.FromFile(file));

You must build your project for windows. You do this by adding -windows to your current Target Framework Moniker (TFM) in the project file:您必须为 windows 构建项目。您可以通过将-windows添加到项目文件中当前的目标框架名字对象 (TFM)来执行此操作:

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net7.0-windows</TargetFramework>
    ...
  </PropertyGroup>

This tells the compiler that you will be running your application exclusively on windows.这告诉编译器您将在 windows 上独占运行您的应用程序。

If you are using winforms, also add如果您使用的是 winforms,还要添加

    <UseWindowsForms>true</UseWindowsForms>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IronPDF 对 System.Drawing.Common 的依赖 - IronPDF dependency on System.Drawing.Common 无法在 DLL 的类中加载依赖项 system.drawing.common - Cannot load dependency system.drawing.common in a class in a DLL System.drawing.common 'gdip' 的类型初始值设定项抛出异常 - System.drawing.common the type initializer for 'gdip' threw an exception System.Drawing.Common DrawString 无法在 Linux 中正确呈现文本 - System.Drawing.Common DrawString not rendering text properly in Linux 为什么无法删除System.Drawing并替换为NuGet包System.Drawing.Common - Why unable to remove System.Drawing and replace with NuGet package System.Drawing.Common .NET Core System.Drawing.Common PrintDocument在Linux上不起作用 - .NET Core System.Drawing.Common PrintDocument doesn't work on Linux 如何在使用“.NETFramework,Version=v4.5.2”的项目中安装 System.Drawing.Common? - How do I install System.Drawing.Common in a project that uses '.NETFramework,Version=v4.5.2'? 使用 C#.net5.0 但没有 System.Drawing.Common 获取/设置图像文件的分辨率? - Get/set the resolution of an image file using C# net5.0 but without System.Drawing.Common? 在 AWS Lambda 上使用 System.Drawing.Common NuGet 包时无法加载 DLL“libdl” - Unable to load DLL 'libdl' when using System.Drawing.Common NuGet package on AWS Lambda 在 Mac OS X 上使用 System.Drawing.Common 将 BMP 转换为 TIFF - Convert BMP to TIFF using System.Drawing.Common on Mac OS X
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM