How do I install System.Drawing.Common in a project that uses '.NETFramework,Version=v4.5.2'?

28,109

Solution 1

in NuGet put this line : Install-Package System.Drawing.Common -Version 4.5.2

in .NET CLI put : dotnet add package System.Drawing.Common --version 4.5.2

in Paket CLI put : paket add System.Drawing.Common --version 4.5.2

Solution 2

Had the same problem. I have cloned solution https://github.com/barnhill/barcodelib . It has two projects: library project targets .Net Standard 2.0 and refers to System.Drawings.Common. Example project depends on library and has reference to System.Drawings.Common. Example project was not compiling due to same error.

My solution was just to remove reference to System.Drawings.Common in nuget packages and readd it (rclick on Example project > Manage nuget packages > Browse Installed, remove the System.Drawings.Common package, and then add it back), unload project and then reload it again

Helped for me.

Solution 3

I managed to solve it by restarting Visual Studio, changing the framework to 4.6.1 (which I could not do before) and adding the reference.

OP's solution migrated from the question to an answer.

Share:
28,109
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    I am trying to write some unit tests in C# in a '.NETFramework,Version=v4.5.2' application but all tests give the next error:

    'System.IO.FileNotFoundException : Could not load file or assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.'

    When I try to install System.Drawing.Common I get the next error from the NuGet package:

    Could not install package 'System.Drawing.Common 4.5.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5.2', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

    I cannot change the application version or the framework (.NET Core 2.1) and any other trick I found online did not work (or generated more errors).

    Help?

  • Admin
    Admin about 5 years
    That's where I got the second error. I did not even find System.Drawing in the Manage nuget ... for solution
  • Admin
    Admin about 5 years
    I tried installing it directly and adding it to the project, but it won't see my dll. I use System.Drawing for one line only(I need to get the dataset from a report design to compare) and I cannot modify the entire solution for my test project
  • ayman lys
    ayman lys about 5 years
    Add : System.Drawing.Bitmap System.Drawing.BitmapData System.Drawing.Brush System.Drawing.Font System.Drawing.Graphics System.Drawing.Icon
  • mietghar
    mietghar about 5 years
    You said that you wanted to write some unit tests, last time I saw an issue when someone was not able to add reference to MS Test project so he had to rebuild whole solution and turn off and on again whole Visual Studio... But I rather guess that your problem is related with your framework version. Do you try to add reference through nuget to all your solution or only your .net core 2.1 project? You could try to update .net framework version to compatible to .net standard 2.0 docs.microsoft.com/pl-pl/dotnet/standard/net-standard