'Could not load file or assembly 'System.Windows.Forms... ' exception
Calling SomeFunction from a referenced Dll in the console application
class Program
{
static void Main(string[] args)
{
SomeFunction();
}
}
throws the exception
{"Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.":"System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"} System.IO.FileNotFoundException
According to this and other answers, the problem could be a .Net version mismatch. The referenced dll that provides SomeFunction targets .NET Framework 4.8, while the Console Application targets .NET 5.0. (.NET 4.8 can't be selected here, only several versions of .NET core are available from the dropdown).
How can I fix this problem?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
