Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET Standard 2.0, WCF Connected Service (Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.2.0.0) #2546

Closed
cabadam opened this issue Feb 7, 2018 · 18 comments
Assignees
Labels
bug This is a product bug. tooling An issues related to any tool shipped from this repo.
Milestone

Comments

@cabadam
Copy link

cabadam commented Feb 7, 2018

This is essentially the same thing that was reported in #2111.

  1. Create a trivial WCF service (the one that comes from the VS template is fine).
  2. Create a .NET Standard 2.0 library, and add a Connected Services item to this WCF service.
  3. Create a Desktop console (.NET 4.6.2 in my case) and reference the .NET standard class library.
  4. Create an instance of the WCF client object and execute a call.
  5. Observe that the application throws an exception on startup:

Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

  1. Try the workaround mentioned in VS2017 WCF Connected Service (Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.1.1.0 at runtime) #2111 of modify the .NET standard library's csproj file to have the following instead of a single TargetFramework:
    <TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
  2. Re-run the console application. It will now get slightly further, before failing on:

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

Similar reports:
https://www.codeproject.com/Questions/1198295/Do-I-need-to-install-NuGet-package-on-NET-standard
https://social.msdn.microsoft.com/Forums/vstudio/en-US/954059c8-adb6-4fe2-939a-e60da1587545/do-i-need-to-install-nuget-package-on-net-standard-library-or-executable-project-or-both?forum=wcf

Even if the workaround were to work, I'm not sure that would be the right answer, as now two DLLs are created, one for .NET Standard 2.0, and one for .NET 4.6.2. That seems like it defeats the purpose of .NET Standard?

@cabadam
Copy link
Author

cabadam commented Feb 7, 2018

I uploaded a sample solution demonstrating this:
https://github.com/cabadam/dotnet-wcf-2546

@mlacouture mlacouture self-assigned this Feb 8, 2018
@mlacouture
Copy link
Member

Hi @cabadam
Thank you for reporting this issue. We will look into it.

@mlacouture mlacouture changed the title .NET Standard 2.0, WCF Connected Service .NET Standard 2.0, WCF Connected Service (Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.2.0.0) Feb 8, 2018
@mlacouture mlacouture added tooling An issues related to any tool shipped from this repo. bug This is a product bug. labels Feb 8, 2018
@zhenlan zhenlan added this to the S131 milestone Feb 9, 2018
@PeterMontgomery777
Copy link

PeterMontgomery777 commented Feb 15, 2018

I was experiencing the same problem but in my case the console test app is also .net core 2.0... but then I realised that if I added System.ServiceModel.Primitives (followed by System.ServiceModel.Http) with NuGet, which gave me version 4.4.1 of each it worked. I'm new to working with .Net core and finding this all a bit confusing right now!

@electricessence
Copy link

This is an issue for me because I have a 'connected service' in my ASP.NET Core 2 web application. If I remove the connected service. dotnet publish works without issue. But this isn't an option for me. I need the connected service. :(

@azbest208
Copy link

Same for me, but the exception is thrown when I connect to WCF service impersonated. Without impersonation works without issues.

@MSGaryWang
Copy link

WCF Connected Service would add "System.ServiceModel.Http" NuGet package to your netstandard2.0 library but this dependency won't be picked up by your console app project even it does reference to that netstandard2.0 library. The workaround is adding the same "System.ServiceModel.Http" NuGet package to your console app project by yourself so it would be referenced correctly. You can do this by using "Manage NuGet Package" menu item or just updating the packages.config file, for example

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="System.ServiceModel.Http" version="4.4.1" targetFramework="net461" />
  <package id="System.ServiceModel.Primitives" version="4.4.1" targetFramework="net461" />
</packages>

Please let me know if this solution working for you.

@electricessence
Copy link

@MSGaryWang I'll try it next week

@zhenlan zhenlan modified the milestones: S131, S132 Feb 24, 2018
@TobiasWen
Copy link

@MSGaryWang I had the exact same problem as the issue creator and for me your advice was at least a workaround to get things done. Thank you for that!

@mbasaran
Copy link

@MSGaryWang That solved the issue for me. Thanks.

@cabadam
Copy link
Author

cabadam commented Mar 3, 2018

@MSGaryWang I can confirm this does workaround the issue. For clarity: Is manually adding these references the intended solution? Or is the dependency supposed to be picked up automatically? (I'm hoping for the latter)

@MSGaryWang
Copy link

We will pass this issue to another team since this is not a WCF only problem but how netstandard library integrated with other project.

@Saritha535
Copy link

I am also facing the same issue. I am using window forms not the WCF.
Could not load file or assembly 'System.ServiceModel.Primitives, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Please could you assist to solve this issue.

@AndyBevan
Copy link

AndyBevan commented Mar 20, 2018

In my scenario I had a framework project referencing my netstandard library. I found that I had to add <RestoreProjectStyle>PackageReference</RestoreProjectStyle> to the framwork Project csproj file in addition to adding the nuget packages System.ServiceModel.Http and System.ServiceModel.Primitives

@Saritha535
Copy link

Which version you added reference for System.ServiceModel.Http and System.ServiceModel.Primitives from nuget packages.

@AndyBevan
Copy link

AndyBevan commented Mar 20, 2018

Actually - I believe that to use my Standard Library from netframework I only had to add <RestoreProjectStyle>PackageReference</RestoreProjectStyle> to the framework csproj.

I used System.ServiceModel.Http and System.ServiceModel.Primitives version 4.4.1 within my standard and dotnet core projects.

Is your windows forms project netframework or standard?

@zhenlan
Copy link
Member

zhenlan commented Apr 17, 2018

Related to dotnet/standard#410.

@x6060x
Copy link

x6060x commented Nov 6, 2019

What fixed the issue for me was adding:
<Reference Include="System.Net.Http" />
in the WCF project (using 4.7.2) and adding:

<add assembly="System.Net.Http, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
to the web.config -> system.web -> compilation -> assemblies.

After doing this I was finally able to use HttpClient in the WCF project.

@AlpeshValvi123
Copy link

I have added these two packages from NuGet and its work for in .Net Console and MVC Core Web App but not working MVC 5 web application.

  1. System.ServiceModel.Http
  2. System.ServiceModel.Primitives

The application is just waiting for a response.

So it's not supported for MVC 5 Application?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a product bug. tooling An issues related to any tool shipped from this repo.
Projects
None yet
Development

No branches or pull requests