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 Core 2.0 self-contained app: Could not load file or assembly 'System.Private.ServiceModel, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

See original GitHub issue

Hi,

I’m migrating a console application to .NET Core 2.0 and when I run the app on my server I’m receiving this message:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Private.ServiceModel, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Private.ServiceModel, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

This app is self-contained and has a netstandard2 library dependency that uses the System.ServiceModel.Http package to call an external api (using WCF).

When I publish the app using the win-x64 runtime identifier the file System.Private.ServiceModel.dll is not placed in the output folder.

If I use the win81-x64/win10-x64 runtime identifiers the file is placed in the output folder.

Is this the correct behavior?

Thanks!

Fabiano

How to simulate

  1. Create the project: dotnet new console

  2. Update the csproj to:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.ServiceModel.Http" Version="4.4.0" />
  </ItemGroup>

</Project>
  1. Update the Program.cs to:
using System;
using System.ServiceModel;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            var binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport)
            {
                MaxReceivedMessageSize = 5242880
            };


            Console.WriteLine("Hello World!");
        }
    }
}
  1. Publish the project: dotnet publish --configuration Release --runtime win-x64

  2. Execute the exe file on the publish folder

dotnet --info output

.NET Command Line Tools (2.0.2)

Product Information:
 Version:            2.0.2
 Commit SHA-1 hash:  a04b4bf512

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.15063
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.0.2\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

Issue Analytics

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

github_iconTop GitHub Comments

7reactions
StephenBonikowskycommented, Jan 19, 2018

4.5.0 packages all have “win” RIDs now as well as “win7” RIDs for netstandard2.0 and netstandard1.3 respectively.

6reactions
breddynetcommented, Feb 22, 2019

Workaround add this to your build process

 <Target Name="BuildProces" BeforeTargets="Build">
    <Copy SourceFiles="$(USERPROFILE)\.nuget\packages\system.private.servicemodel\4.5.3\runtimes\win\lib\netstandard2.0\System.Private.ServiceModel.dll" DestinationFolder="$(OutputPath)\bin" />
  </Target>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Generation failed, error code Rejected when use the new ...
1> Primary reference "System.Runtime.Serialization.Formatters, Version=4.0.2.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