You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS2017中F#/.NET Standard2.0项目无法识别System.Drawing.Bitmap

Fixing "The type 'Bitmap' is not defined in 'System.Drawing'" in F# .NET Standard 2.0 Projects

Hey there, let's break down why you're running into this issue and how to fix it quickly. The core problem here is that .NET Standard 2.0 doesn't include the full System.Drawing APIs out of the box—the traditional System.Drawing reference you're trying to add is tied to .NET Framework, not .NET Standard. Here's what you need to do:

Step 1: Remove any existing System.Drawing references

First, get rid of any manual System.Drawing references you added to your project. These are likely pointing to the .NET Framework version, which won't work properly with .NET Standard.

  • Right-click your project in Solution Explorer > Manage NuGet Packages
  • Go to the "Installed" tab, find any System.Drawing entries, and uninstall them
  • Also check your project file (.fsproj) to make sure there are no leftover <Reference Include="System.Drawing" /> lines—delete them if present

Step 2: Install the official System.Drawing.Common NuGet package

Microsoft provides a dedicated NuGet package for System.Drawing in .NET Standard/.NET Core projects: System.Drawing.Common. This is the only supported way to use Bitmap and other GDI+ APIs in your project.

You can install it in two ways:

Option A: Using Visual Studio's NuGet Package Manager

  • Right-click your project > Manage NuGet Packages
  • Go to the "Browse" tab, search for System.Drawing.Common
  • Select the package (make sure it's published by Microsoft) and click "Install"

Option B: Using the .NET CLI

Open a terminal in your project directory and run:

dotnet add package System.Drawing.Common

Step 3: Verify the reference is correctly added

Check your .fsproj file to confirm the package is listed. You should see a line like this:

<PackageReference Include="System.Drawing.Common" Version="x.x.x" />

(Replace x.x.x with the stable version you installed—ensure it's compatible with .NET Standard 2.0.)

Step 4: Test with a simple F# code snippet

Add a quick test to make sure Bitmap is now recognized:

open System.Drawing

let testBitmap = new Bitmap(100, 100)
// Do something with testBitmap, like save it
testBitmap.Save("test.png")
testBitmap.Dispose()

Build your project—this should compile without the "type not defined" error now.

Important Notes

  • Cross-platform considerations: While System.Drawing.Common works seamlessly on Windows, it has limited support on Linux/macOS (it requires libgdiplus to be installed). If you're targeting non-Windows platforms, consider alternatives like ImageSharp or SkiaSharp for image processing.
  • Avoid mixing references: Never add both the .NET Framework System.Drawing reference and the System.Drawing.Common NuGet package—this will cause conflicts.

内容的提问来源于stack exchange,提问作者Aphex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:40:08