console-application.net-6.0compatibility.net-framework-versionclass-library

.NET Framework 4.5.2-based Console application compatibility problems with .NET 6-based Class Library project


Here is the info associated with the development environment:

I have a Console project created using:

I have a Class Library project created using:

Within Visual Studio 2019, I was trying to reference the Class Library DLLs in the Console project, and fortunately, it did not throw any errors. It built properly, and there were no errors.

However, when I run the .NET Framework 4.5.2-based Console application as a standalone, it throws the following errors:

System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>

I checked the Nuget Package Manager, and I only found the following latest version

System.Runtime Version 4.3.1 (latest version)

It’s strange that the Exception complains about a System.Runtime, Version=6.0.0.0

However, Nuget package Manager states that the latest System.Runtime’s Version is 4.3.1

In any case, I did successfully install the latest System.Runtime’s Version 4.3.1 into my .NET Framework 4.5.2-based Console project. Furthermore, it built properly, and there were no errors.

However, again, when I run the .NET Framework 4.5.2-based Console application as a standalone, it throws the following errors:

System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>

How can I resolve the aforementioned compatibility problems?


Solution

  • @hans-passant Thanks for the comment.

    Incidentally, I just wanted to mention the following.

    Using the .NET6-based Class Library with the .NET Framework 4.5.2-based Solution led to compatibility problems.

    After doing some investigation & research, we could look into the option of refactoring said Class Library so that it can accommodate multiple client project that have different .NET frameworks. Here are some of the following relevant technical guides: