1

I am new to C# and I am trying to create a bitmap object in C# in Visual Studio 2019, but it isn't working. I have .NET Framework updated to the latest version and I have resharper installed. I am using Windows 10.

Ive tried adding the references manually with Add/Reference... and it does not stay checked.
I added using system.drawing and using system.drawing.common to the top of my code.
I updated my .net core and enabled it in my project.

using System;
using System.Drawing.Common;

namespace Bot
{
    class Program
    {
        static void Main(string[] args)
        {
            var bmp = new Bitmap();
        }
    }
}

I expected it to create a bitmap object, but it won't compile and gives me errors saying that the bitmap object does not exist in system.drawing.

GSerg
  • 76,472
  • 17
  • 159
  • 346
Chris Ray
  • 41
  • 1
  • 3
  • 1
    You need to add reference to ```System.Drawing.dll```, read the instructions [here](https://stackoverflow.com/questions/8553136/system-drawing-namespace-not-found-under-console-application). – Adir Ratzon May 04 '19 at 17:30
  • Have you installed the `System.Drawing.Common` NuGet package? When you have, add `using System.Drawing;`, then write `var bmp = new Bitmap(1, 1);` (you need to specify a size or a source Image or a file path or a stream). – Jimi May 04 '19 at 17:40
  • How do I install that? Sorry, I just started learning C# and VS a month ago – Chris Ray May 04 '19 at 17:50
  • `Tools -> NuGet Package Manager - Manage NuGet Packages for Solution`. Search `System.Drawing.Common` and install it, ticking all the checkboxes (`Project`) you find in the panel on the right. – Jimi May 04 '19 at 18:21
  • 1
    What are you targetting: Winforms, WPF, ASP..? YOU should __always__ TAG your questions correctly so one can see it on the questions page! In your case do Tag .NET Core! – TaW May 04 '19 at 19:23

2 Answers2

2

The Bitmap class if part of the assembly System.Drawing.Common.dll, so you need to install System.Drawing.Common via the Nuget Package.

Ran Turner
  • 14,906
  • 5
  • 47
  • 53
0

It looks like you don't have the package in your system/project. In you're project directory or from VScode terminal do this:

dotnet add package System.Drawing.Common --version 6.0.0

then add a reference to the package in you're project

Ahmed Ali
  • 1
  • 2