wcf icon indicating copy to clipboard operation
wcf copied to clipboard

wcf library components 6.0.0 exception: 'Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.'

Open leon-tliang3 opened this issue 2 years ago • 18 comments

Describe the bug 'Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.'

To Reproduce Steps to reproduce the behavior:

  1. Creates a .net application (.net 6.0) using wcf library components System.ServiceModel.** (Http, NetTcp and Duplex, etc.) v4.10.2 [https://github.com/dotnet/wcf/releases/tag/v3.4.1-rtm] and wcf service (.net framework 4.8).
  2. .net application registers duplex communication with wcf service.
  3. Upgrades wcf library components to [v6.0.0] (https://github.com/dotnet/wcf/releases) from v4.10.2, then it will throw an exception that 'Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.'.
  4. I tried to fix it through add NuGet package System.ServiceModel.Primitives to reference, but it still have the same error.

Expected behavior It should be worked just like v4.10.2 after upgrading the wcf library components to v6.0.0.

Screenshots image

leon-tliang3 avatar Sep 13 '23 07:09 leon-tliang3

This looks like it's caused by a breaking change in the 6.* version of WCF client packages, documented at https://learn.microsoft.com/en-us/dotnet/core/compatibility/wcf-client/6.0/net-standard-2-support , you can refer to the document's Recommended action section to resolve the issue.

imcarolwang avatar Sep 13 '23 08:09 imcarolwang

Thanks Carol. I removed references to the System.ServiceModel.Duplex and System.ServiceModel.Security from the .net application reference list below, but it still has the same issue... Do you know why? image

leon-tliang3 avatar Sep 13 '23 08:09 leon-tliang3

As the document indicated, I think you'll need to multi-target your WCF libraries in your project file. Specifically, add a conditional assembly reference to System.ServiceModel.dll for .NET Framework and conditionally add package references to WCF Client packages for .NET.

For example: image

imcarolwang avatar Sep 13 '23 09:09 imcarolwang

Please forgive me, I'm new here. I changed the .csproj file of the .net application to the following, but it still has the same error... image

leon-tliang3 avatar Sep 13 '23 09:09 leon-tliang3

Sorry to hear that the issue persists. Is it possible for you to share a sample repro project?

imcarolwang avatar Sep 13 '23 10:09 imcarolwang

Let me briefly describe the project first, if it needs to the source code, I will split it out my solution.

  1. I create a duplex connection class used for the client (wrote by .net framework 4.8) to establish the duplex communication with WCF service (.net framework 4.8).
  2. Then I create a .net application (.net 6.0), and also want to establish the duplex communication with this WCF service, so I inherited this duplex connection class to register the duplex communication with WCF service.
  3. In WCF Client packages v4.10.2, it is compatible with .net and .net framework, so System.ServiceModel.dll can used for .net application when registering the duplex communication.
  4. But in WCF Client packages v6.0.0, I debugged the code and failed even if I add the System.ServiceModel (under .net framework 4.8 assembly directory) into .net project reference list. I guess it is because of this System.ServiceModel.dll is NOT compatible with .net 6.0 project. Since the new version 6.0 has used the new NuGet System.ServiceModel.Primitive, why the .net application still try to find the System.ServiceModel assembly? If it is used for the base duplex connection class (.net framework), this System.ServiceModel.dll is in the same folder with .net application, why it can not found or load this dll? I don't know this System.ServiceModel assembly is used by class in .net project or .net framework project.

leon-tliang3 avatar Sep 14 '23 06:09 leon-tliang3

@leon-tliang3 Thanks for the update. I was able to reproduce the issue by creating a client project targeting net6.0, which referenced a net4.8 project and the wcf library was used in the net4.8 project. Do you think updating target of the net4.8 project to netstandard2.0 is an acceptable workaround? From what I understand, when a net6.0 project references a net4.8 project, compatibility between them cannot be guaranteed.

imcarolwang avatar Sep 14 '23 09:09 imcarolwang

@imcarolwang Thanks for your quick response. From what I understand, System.ServiceModel.Primitive target only .NET 6. Library projects. If .net4.8 has the compatible issue with .net 6.0 when reference this NuGet package, why there is no compatible issue between .net6.0 and netstandard2.0? Besides, I‘m afraid I cannot update net4.8 project to netstandard2.0, because that is take a lot of effort to do that, Is there any other workarounds? Or will MS fix this issue in future version of System.ServiceModel.Primitive? Maybe be 7.0 or 8.0?

leon-tliang3 avatar Sep 14 '23 09:09 leon-tliang3

Regarding why there is no compatible issue between .net6.0 and netstandard2.0? This document might be helpful to answer the question, it's because net6.0 implemented netstandard2.0.

imcarolwang avatar Sep 14 '23 09:09 imcarolwang

@imcarolwang I saw that it removed the support for .netstandard2.0 from WCF Client v6.0 in section Reason for change in document.

The change to remove support for .NET Standard was made so that WCF Client and WCF Client apps can take advantage of the new features and APIs available in .NET 6 and later versions.

I don't know if this is what I understand. But this is not the point, I mean even net48 and netstandard2.0 are compatible, I probably wouldn't be able to update it. I just would like to know if there any other workarounds besides this? It's really important for me. Thank you in advance.

leon-tliang3 avatar Sep 15 '23 00:09 leon-tliang3

Is there any update?

leon-tliang3 avatar Sep 27 '23 07:09 leon-tliang3

In my case, I have dotnet 8 reference to a framework4.8 project. The error remained even I have system.servicemodel.promitives installed. End up, I have downgraded system.servicemodel.promitives from v8 to v4.10.3 (the latest for v4)

hankpotter avatar Jun 20 '24 17:06 hankpotter

@hankpotter system.servicemodel.promitives 4.10.3 only support .net 6.0, but not .net 8.0, but .net 6.0 will end to support on Nov 12, 2024.

leon-tliang3 avatar Jun 25 '24 03:06 leon-tliang3

I do not use servicemodel in .net 8. It is required to include in .net 8 in order to call a function inside framework4.8..

I have tried servicemodel v8 and v6. Only v4.10.3 can get rid of the following error Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0

hankpotter avatar Jun 25 '24 17:06 hankpotter

@hankpotter, I'm working on a solution for this. We've extended the support date for the 4.10.3 version so that there's a supported version available for this scenario.

mconnew avatar Jun 26 '24 17:06 mconnew

Hi, we also encountered the problem. Will there be a fix soon?

hwsmo avatar Jul 18 '24 10:07 hwsmo

Hi, is there any news on the current development status?

hwsmo avatar Aug 26 '24 07:08 hwsmo

@mconnew is there any update? And I know that you extends the end of support date for WCF Client 4.10 until November 12, 2024, but I would like to know that is there any possible to extend the date further? Because if there is no suitable solution, we may need enough time to migrate the code from .NET Framework to .NET.

leon-tliang3 avatar Sep 11 '24 05:09 leon-tliang3