9

I need to reference a proprietary-client library that only works with .NET 4.8, there is no other option, this is a very narrow vendor library and we have to use it with .NET 48.

The new app that is being developed is a service application and will need to be maintained in the long term. And it's ok for this app to be installed on windows only. But we would like the application to benefit from .NET 6, while being able to use the .NET 4.8 client library.

So my question is : what would/could be a good solution that:

  1. respects that I need some code in 4.8 to work with that library.
  2. leverages .NET 6 and future enhancements

Thanks for your help!

codea
  • 1,439
  • 1
  • 17
  • 31
  • You can't have .NET and .NET Framework code together, that cannot even compile to begin with. If you get it to compile somehow, it will fail at runtime (under .NET 6) due to the missing libraries. You will need 2 separate applications and use some sort of communication method between them – Camilo Terevinto Nov 09 '21 at 14:17
  • 1
    If the library relies on WCF, then you're stuck: WCF isn't available (at least in the same form) on .NET 6 – canton7 Nov 09 '21 at 14:17
  • 1
    @CamiloTerevinto that's not true, you can reference .NET 4.8 from .NET 6 and it will compile. And in many cases it will then NOT fail at runtime even. In other cases though it will. – Evk Nov 09 '21 at 16:47
  • @Evk I was talking specifically about this scenario, where WCF libraries are referenced – Camilo Terevinto Nov 09 '21 at 16:52
  • @codea `this is not the topic, ` actually it is. WCF is a library, not a protocol. The underlying protocol is SOAP, .NET Remoting or perhaps a custom protocol created by the vendor. Remoting went out of fashion 15 years ago and 8very* few servers use it. Nothing prevents you from creating and using a WCF client for SOAP using eg the `Connected Services` option in Visual Studio or the `svcutil` command-line tool. What protocol does the server use? – Panagiotis Kanavos Nov 10 '21 at 11:55
  • If the server uses .NET Remoting you're out of luck - that protocol was essentially abandoned 15+ years ago and not migrated to .NET Core because it's simply not used by developers. Everyone since the mid-2000s uses either SOAP or lately, gRPC and REST-y HTTP APIs. Unless someone wanted to *ensure* customers would have to buy the client from the vendor – Panagiotis Kanavos Nov 10 '21 at 11:59
  • If the service does use Remoting a) it's probably time to find a new vendor and b) you could create an "proxy" .NET Old service that talks using Remoting to the legacy service and SOAP, HTTP or whatever you want to your .NET Core application. – Panagiotis Kanavos Nov 10 '21 at 12:02
  • To share, we decided to develop against .NET 4.8 for the time being as this was providing all we needed. – codea Jan 28 '22 at 07:53

2 Answers2

10

Yes you can reference .NET 4.8 assembly from .NET 6. However, there are no guarantees it will work as expected. It will work only if it does not use any APIs which are not present in .NET 6 (or rather .NET Standard version supported by .NET 4.8), and if APIs it uses did not have breaking (for that application logic) changes.

You can easily test it by creating .NET 4.8 library with something like this:

public class Test
{
    public static void OldNet()
    {
        Console.WriteLine("Hello from old .NET");
    }
}

Then reference it from .NET 6 and call:

 OldNet4.Test.OldNet();

Run and it will print "Hello from old .NET" no problem.

However if you for example use Thread.Abort in that old .NET 4.8 library - when running on .NET 6 it will not abort the target thread but instead will throw PlatformNotSupportedException, which is an example of breaking change. If it calls missing api, then it will throw TypeNotFound or similar exceptions.

So the end result depends on the library being referenced.

Evk
  • 98,527
  • 8
  • 141
  • 191
0

Yes, it is possible to have a client written in .NET Framework 4.8 and a server in .NET Core 6. It's possible to have a client and a server written in different programming languages as well, so there's no reason that your use case wouldn't be possible. However, it's not possible to reference a .NET Core assembly from a .NET Framework assembly.

Arun_Raja1
  • 207
  • 1
  • 1
  • 1
    "Yes, it is possible to have a client written in .NET Framework 4.8 and a server in .NET Core 6" -> this question is specifically about WCF, and so far, it is not possible to have a WCF Server in any .NET Core/.NET version. – Camilo Terevinto Nov 09 '21 at 16:56