Search code examples
.netsystem.drawinginvalidoperationexception

Could not load file or assembly 'System.Drawing' or one of its dependencies


I'm getting this error since yesterday and after 'searching trying and crying' I've ended up asking the question on here.

An unhandled exception of type 'System.InvalidOperationException' occurred in 'project.exe'

The error is: Could not load file or assembly 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

This project is set to use the 3.5-Framework. The error occurs when the form loads, when my resources have images or anything that uses graphics in it. (removing the form-icon and button-images 'solves' the problem). I've allready tried the following :

  1. Performed a 'Clean' & 'Rebuild' on the project
  2. Removed the System.Drawing reference, and added it back in.
  3. Set accessmodifier for the resource in the *.resx to 'no code generation'.
  4. Searching the *resx-file for '4.0.0.0' to replace with '2.0.0.0' but '4.0.0.0' was not listed anywhere.

This question has been raised in the past, yet no suggestions seem to fix my problem ?

Thanks for reading. Thanks for your time. Bert


Solution

  • As I tried to remember what changed before this error started to occur, i remember setting a System variable I set :

    System var

    Trying to fix the buggy error

    MSBUILD : error MSB4017: Could not run the "GenerateResource" task because MSBuild could not create or connect to a task host with runtime "CLR2" and architecture "x86".

    1. Closed Visual studio
    2. Removed said System Variable
    3. Rebuild solution (without even editing any icons/images)

    Now it works ... Strange !