question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 #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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
MSGaryWangcommented, Feb 24, 2018

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.

1reaction
AlpeshValvi123commented, Oct 22, 2020

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core 2.0 Could not load file or assembly System. ...
NETCore.App\2.0.0" folder and I see a System.ServiceModel.Web.dll. I'm not doing any WCF work and as ...
Read more >
Cannot load file or assembly 'System.Runtime'
The system cannot find the file specified. Here is the log: Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.
Read more >
Troubleshoot .NET Framework targeting errors
To resolve the error, make sure that your application targets a .NET version that's compatible with the version that's targeted by the projects ......
Read more >
System.Net.Http NuGet broken for .NET 4.7.2 · Issue #26131
Net.Http.dll hell, I got the same error: Could not load file or assembly 'System.Net.Http, Version=4.0.
Read more >
https://raw.githubusercontent.com/dotnet/samples/m...
FileLoadException: Could not load file or assembly 'System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found