1

I am porting projects in Visual Studio from .NET Framework 4.X to .NET 6.0, and was helpfully told by the compiler that some functions have moved around, for example System.Drawing.Bitmap is now within System.Drawing.Common, and SystemEvents.DisplaySettingsChanged is now within Microsoft.Win32.SystemEvents - which aren't within the core framework.

I used NuGet to install these (as they weren't within the COM list in Reference Manager). The project builds, everything is targeting .NET 6.0, but I get runtime errors of, e.g.:

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

I found another semi-similar post suggesting adding <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> to the .csproj file, but this hasn't worked either - the .dlls are added to bin\Debug\net6.0\ folder where the .exe is, but still aren't recognised during execution.

What am I missing here?

white-wolf97
  • 106
  • 1
  • 3
  • 12
Haighstrom
  • 577
  • 5
  • 16
  • Does the file that is missing actually exist in your bin folder (next to the exe) and does it have the correct version? – PMF Nov 13 '21 at 20:54
  • Yes, it is in fact there, too. – Haighstrom Nov 13 '21 at 21:03
  • Yesterday I had same strange issue but with .NET 5 target. .NET6 SDK and VS2022. Deleting all bin and obj folders helped me. – Pavel Voronin Nov 13 '21 at 21:21
  • @PavelVoronin OK well that has at least changed the error. Now I'm getting System.PlatformNotSupportedException: 'System.Drawing.Common is not supported on this platform.' (I'm on Win10). Seems like it might be a version issue, but everything is showing as 6.0. – Haighstrom Nov 13 '21 at 21:34
  • That error is typically a result of an incorrect binding resolution for multi-platform assemblies. You might need to set the `` property to `net6.0-windows`. – PMF Nov 14 '21 at 13:07
  • @PMF nope, didn't changed anything. I had it set to .net6.0 intentionally, as the code that is Windows-specific (System.Drawing.Bitmap in this example) is only for the Windows implementation of an interface (this project is an engine similar to OpenTK). But in any case making it windows-specific target didn't fix it. – Haighstrom Nov 14 '21 at 17:40
  • Sigh - I hadn't included the xcopy command in pre-build events to bring assets into the relevant bin folder. So the actual error is that the path giving to the Bitmap constructor was not found. Why on earth am I not getting back the real Exceptions from Bitmap? – Haighstrom Nov 14 '21 at 17:48
  • 1
    The constructor of `System.Drawing.Bitmap` is known to throw random exceptions if something is wrong. Never rely on the message it gives. Any exception it throws just means "something didn't work". – PMF Nov 14 '21 at 17:53
  • @PMF OK. It used to give me the right errors in .NET Framework 4.8, but fine - I have seen such things with pinvokes. Would you recommend I delete this question? It doesn't seem particularly reuseable for people. – Haighstrom Nov 14 '21 at 18:04
  • The resolution apparently had little to do with the original problem, so deleting would be an option. However, I think you cannot delete questions that got upvoted. – PMF Nov 14 '21 at 18:20

0 Answers0