Irina Gutanu
Irina Gutanu

Reputation: 131

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

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?

Upvotes: 13

Views: 70573

Answers (5)

ayman lys
ayman lys

Reputation: 169

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

Upvotes: 13

Ivan P.
Ivan P.

Reputation: 946

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 read 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

Upvotes: 4

TylerH
TylerH

Reputation: 21067

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.

Upvotes: 1

renaissanceMan
renaissanceMan

Reputation: 433

This is kind of bizarre but it worked dramatically so I'm going to mention it. I built a small vs 2017 ent console project that was supposed to read an oracle database. When I started to run it I got the System.Drawing.Common error mentioned above. It seemed stupid because I wasn't really doing anything having to do with Drawing at all. In Manage Nuget Packages I deleted the Oracle.ManagedDataAccess driver and added the Oracle.ManagedDataAccess.Core and the System.Drawing.Common error went away and I was able to read my oracle database. So I'm suggesting that with NuGet you may be picking up some things you really don't need and if you have any choice for your NuGet packages, try different ones. This also may be some foible with how my organization managed nuget for Visual Studio 2017 enterprise.

Upvotes: 2

mietghar
mietghar

Reputation: 93

you could try to use one of the libs described in here instead https://devblogs.microsoft.com/dotnet/net-core-image-processing/

you could try to use https://www.nuget.org/packages/CoreCompat.System.Drawing/ as well and maybe try to change your app framework to .net standard 2.0?

Upvotes: 0

Related Questions