1

I'm working with an older C# solution built on .NET Framework 4.8, which contains several libraries. Now, I'm developing a new solution targeting .NET 8 that needs to reuse some of those existing libraries.

For example, the old solution includes a configuration application that manages settings required by the new project, as well as a NetMQ library that handles data synchronization between services and clients. In total, there are eight libraries, some large, some small, that I need to integrate.

I’ve tried referencing the compiled DLLs from the old projects in the .NET 8 solution, but when running the application, I encounter various exceptions. One such example:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http.WebRequest, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Even after adding the corresponding NuGet package, the issue persists. This makes me wonder if it's even feasible to reference complex .NET Framework 4.8 libraries in a .NET 8 project.

Rewriting these libraries would be a significant effort, especially since there’s tight communication between components, and it’s absolutely critical that everything stays in sync.

So, how does this actually work? Is it still possible to reuse .NET Framework 4.8 libraries in a .NET 8 solution—and if so, how?

7
  • NetMQ supports .NET 8 via .NET Standard 2.1 Commented Apr 9 at 14:14
  • You should multi-target the libraries to support modern .NET (e.g. by adding netstandard2.0 in additional to net481). Commented Apr 9 at 14:22
  • 1
    Short version would be "no"; longer version would be multi-targeting; I'm going to be contrarian and strongly suggest against netstandard - it is almost always preferable to target specific platforms, i.e. <TargetFrameworks>net48;net8.0</TargetFrameworks>) Commented Apr 9 at 14:25
  • 1
    It is possible, but they can break unexpectedly. Libraries may need type forwarders. Methods may be missing and you get MissingMethodException in weird places, or errors like PlatformNotSupportedException or other different behaviours. Commented Apr 9 at 15:15
  • Thanks! sounds like it's really a no, everything else seems like a very bumpy road, with problems likely to arise when there's the least time to fix them. Commented Apr 9 at 16:03

2 Answers 2

0

Hmm, mixing old .NET Framework 4.8 stuff with .NET 8? I’ve heard people sometimes get it working by tweaking the app.config or using binding redirects to handle version conflicts, especially for missing assemblies like System.Net.Http.WebRequest. Maybe try the .NET Portability Analyzer tool to see which parts of the old libraries are incompatible—though I’m not sure if that’s still a thing. You could also experiment with manually adding assembly references or even copying DLLs directly into the output folder though that feels hacky. Some folks online mentioned creating a facade project that wraps the old libraries, maybe with some compatibility NuGet packages, but I’ve never tried it. Honestly, it might just be easier to bite the bullet and update chunks of the old code incrementally, targeting .NET Standard where possible. But yeah, no guarantees, some dependencies just won’t play nice with the newer framework.

Sign up to request clarification or add additional context in comments.

Comments

0

Can .NET 8 reference assemblies targeting .NET Framework 4.8?

In the purest sense, yes. It's a straight forward test to validate.

  1. Create class library targeting .NET Framework 4.8

    1. Create a new class in this library.
  2. Create console application target .NET 8.

  3. In #2 reference #1.1.

  4. Build and run.

  5. Success.

However, as others have noted it may be impractical to do this in a real world setting with non-trivial dependencies amongst other reasons.

Perhaps the actual answer is "yes but your mileage may vary".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.