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

Closed
fabiano opened this issue Oct 23, 2017 · 21 comments
Assignees
Labels
feature request Adding new functionality requiring adding an API to the public contract.
Milestone

Comments

@fabiano
Copy link

fabiano commented Oct 23, 2017

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
@zhenlan
Copy link
Member

zhenlan commented Oct 24, 2017

The Runtime Identifier (RID) that System.Private.ServiceModel supports on Windows is win7. You can find this by opening up the NuGet package and look at the runtimes folder. The list of supported RIDs for .NET Core is in the runtime.json file. You can see win81-x64 and win10-x64 import win7 (indirectly) so they are S.P.SM compatible RIDs while win-x64 imports win so it's not compatible. The behavior you observed is expected.

@zhenlan zhenlan self-assigned this Oct 25, 2017
@zhenlan zhenlan added this to the S126 milestone Oct 25, 2017
@fabiano
Copy link
Author

fabiano commented Nov 10, 2017

@zhenlan Thanks for the help.

Are you going to support the portable RIDs (win-x64, win-x86)? Or is it best always use the specific for the platform I'm targeting?

@zhenlan zhenlan added the feature request Adding new functionality requiring adding an API to the public contract. label Nov 10, 2017
@zhenlan zhenlan modified the milestones: S126, S127 Nov 10, 2017
@zhenlan
Copy link
Member

zhenlan commented Nov 10, 2017

@fabiano Yes, I think we can support portable RIDs in our next release (likely 2.1). Thanks for bringing this to our attention.

Just a note, we will need to change the RID of S.Private.ServiceModel from win7 to win for Windows. Our linux RID looks good (it's unix).

@zhenlan zhenlan assigned StephenBonikowsky and unassigned zhenlan Nov 10, 2017
@zhenlan zhenlan modified the milestones: S127, S128 Dec 4, 2017
@lkurzyniec
Copy link

Try to add RuntimeIdentifier into csproj. We fixed our AMI Linux build by adding <RuntimeIdentifier>centos-x64</RuntimeIdentifier>

@zhenlan zhenlan modified the milestones: S129, S130, 2.1.0 Jan 12, 2018
@StephenBonikowsky
Copy link
Member

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

@fabiano
Copy link
Author

fabiano commented Jan 19, 2018

Thank you guys!

@gallivantor
Copy link

The latest Microsoft.Windows.Compatibility package (2.0.1) is still pulling in the old 4.1.x System.Private.ServiceModel so this problem is still happening to new apps that reference the Windows Compat Pack, to get around it you have to explicitly add a reference to the latest version of this System.Private.ServiceModel.
Which team is responsible for the Compability Pack, how can we get this fixed?

yecli added a commit to VirtoCommerce/vc-platform-core that referenced this issue Jan 10, 2019
…tem:

- Reworked LoadContextAssemblyResolver assembly loading: every module assembly with all level dependencies is loaded into AssemblyLoadContext.Default to allow shared types to be used;
- Set all module Web projects <CopyLocalLockFileAssemblies> option to true to have the possibility to copy all dependencies from its bin folder (using this approach it should work on prod env where we cannot just restore packages). Futher investigation and revision could be done based on:
https://github.com/dotnet/cli/issues/10502;
- Set <RuntimeIdentifier>win10-x64</RuntimeIdentifier> option to VirtoCommerce.ImageToolsModule.Web project to address problem with NuGet package Microsoft.Windows.Compatibility, which do not copy  its dependency "System.Private.ServiceModel.dll" on publishing. Explicit reference to System.ServiceModel.Http 4.5.3 package did not help, setting RID helped, though it makes module platform dependent. Info:
dotnet/wcf#2349, https://stackoverflow.com/questions/50746592/system-private-servicemodel-missing-in-azure-app-service-at-runtime;
- Removed redundant LoadContextAssemblyResolver singleton registration;
- Changed Windows specific "\" path separator to platform independent Path.DirectorySeparatorChar in LocalStorageModuleCatalog probing folder;
- Fixed Sonar warning in ModuleInitializer.
yecli added a commit to VirtoCommerce/vc-platform-core that referenced this issue Jan 25, 2019
…tem:

- Reworked LoadContextAssemblyResolver assembly loading: every module assembly with all level dependencies is loaded into AssemblyLoadContext.Default to allow shared types to be used;
- Set all module Web projects <CopyLocalLockFileAssemblies> option to true to have the possibility to copy all dependencies from its bin folder (using this approach it should work on prod env where we cannot just restore packages). Futher investigation and revision could be done based on:
https://github.com/dotnet/cli/issues/10502;
- Set <RuntimeIdentifier>win10-x64</RuntimeIdentifier> option to VirtoCommerce.ImageToolsModule.Web project to address problem with NuGet package Microsoft.Windows.Compatibility, which do not copy  its dependency "System.Private.ServiceModel.dll" on publishing. Explicit reference to System.ServiceModel.Http 4.5.3 package did not help, setting RID helped, though it makes module platform dependent. Info:
dotnet/wcf#2349, https://stackoverflow.com/questions/50746592/system-private-servicemodel-missing-in-azure-app-service-at-runtime;
- Removed redundant LoadContextAssemblyResolver singleton registration;
- Changed Windows specific "\" path separator to platform independent Path.DirectorySeparatorChar in LocalStorageModuleCatalog probing folder;
- Fixed Sonar warning in ModuleInitializer.
tatarincev pushed a commit to VirtoCommerce/vc-platform-core that referenced this issue Feb 6, 2019
…tem. (#124)

* - Added tests for module assembly loading;
- Used PluginLoader for this;

* #123 Support module nested references loading in Platform modular system:
- Reworked LoadContextAssemblyResolver assembly loading: every module assembly with all level dependencies is loaded into AssemblyLoadContext.Default to allow shared types to be used;
- Set all module Web projects <CopyLocalLockFileAssemblies> option to true to have the possibility to copy all dependencies from its bin folder (using this approach it should work on prod env where we cannot just restore packages). Futher investigation and revision could be done based on:
https://github.com/dotnet/cli/issues/10502;
- Set <RuntimeIdentifier>win10-x64</RuntimeIdentifier> option to VirtoCommerce.ImageToolsModule.Web project to address problem with NuGet package Microsoft.Windows.Compatibility, which do not copy  its dependency "System.Private.ServiceModel.dll" on publishing. Explicit reference to System.ServiceModel.Http 4.5.3 package did not help, setting RID helped, though it makes module platform dependent. Info:
dotnet/wcf#2349, https://stackoverflow.com/questions/50746592/system-private-servicemodel-missing-in-azure-app-service-at-runtime;
- Removed redundant LoadContextAssemblyResolver singleton registration;
- Changed Windows specific "\" path separator to platform independent Path.DirectorySeparatorChar in LocalStorageModuleCatalog probing folder;
- Fixed Sonar warning in ModuleInitializer.

* #123 Support module nested references loading in Platform modular system:
- Excluded copying assembly related dlls that are in TPA;
- Splitted assembly file extensions (dll, exe) and assembly service file extensions (pdb, xml, .deps.json) for using in filtering;
- Removed unused McMaster.NETCore.Plugins package reference from VirtoCommerce.Platform.Modules.csproj;
- Fixed couple of Sonar warnings;

* #123 Support module nested references loading in Platform modular system:
- Implemented "api/platform/modules/restart" action using IApplicationLifetime.StopApplication();

* #123 Support module nested references loading in Platform modular system:
- Added AdditionalProbingPath filling based on runtimeconfig.json and runtimeconfig.dev.json for Development env + NuGet and DotNet package caches for Production env;
- Removed all NuGet assembly copying to Modules probing folder. So it works on DEV env, for PROD we will need to prepare packages with required dependencies;
- Rebased on the latest master;
Review:
- Reworked test according to https://docs.microsoft.com/en-us/dotnet/core/testing/unit-testing-best-practices;
- Arranged DependencyReader as an extension;
- Other fixes;

* #123 Support module nested references loading in Platform modular system:
- Removed copying NuGet assemblies to output in Module1;
@nero120
Copy link

nero120 commented Feb 20, 2019

@zhenlan I'm confused by this. I'm developing an Azure Function (v2) app in dot net core 2.1 which uses System.ServiceModel.Http 4.5.3 (using System.Private.ServiceModel 4.5.3 in turn). My local RID is win10-x64 and I am not specifying any other RuntimeIdentifier in my csproj file, and I get a similar error to the above:

Could not load file or assembly 'System.Private.ServiceModel, Version=4.5.0.3, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. System.Private.CoreLib: Could not load the specified file.

Looking in the bin\Debug folder, the referenced assemblies are in netcoreapp2.1\bin, but I can't see System.Private.ServiceModel.dll in there.

If I add <RuntimeIdentifier>win-x64</RuntimeIdentifier> into my csproj then referenced assemblies are now in netcoreapp2.1\win-x64\bin and I can see System.Private.ServiceModel.dll in there, but when hitting F5 it fails to even start.

Even downgrading System.ServiceModel.Http to 4.4.4 still fails:

Could not load file or assembly 'System.Private.ServiceModel, Version=4.1.2.4, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. System.Private.CoreLib: Could not load the specified file.

It seems I can't get this to work regardless of the RID used, what am I doing wrong?

@breddynet
Copy link

I am also facing the same issue, Is there any workaround for this?

@breddynet
Copy link

breddynet commented Feb 20, 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>

@nero120
Copy link

nero120 commented Feb 22, 2019

Thanks @breddynet.

@zhenlan @StephenBonikowsky some clarification here would be appreciated, why would the latest version not be included in a build on win10-x64 under dotnet 2.1.503?

@StephenBonikowsky
Copy link
Member

@nero120 I'll look into this today.

@StephenBonikowsky
Copy link
Member

StephenBonikowsky commented Feb 22, 2019

Hi @nero120 while this is an RID issue it isn't with our WCF packages. We do the correct thing based on the .NET Core supported RID's runtime.json file.

The issue is with the Azure Function app, there is an active issue with lots of details regarding this problem.

Azure/azure-functions-host#3568

@nero120
Copy link

nero120 commented Feb 22, 2019

Aha! Thank you very much for looking into this @StephenBonikowsky, I've subscribed to the issue you linked to.

@ehsansajjad465
Copy link

ehsansajjad465 commented Sep 27, 2019

@fabiano Yes, I think we can support portable RIDs in our next release (likely 2.1). Thanks for bringing this to our attention.

Just a note, we will need to change the RID of S.Private.ServiceModel from win7 to win for Windows. Our linux RID looks good (it's unix).

@zhenlan Is this resolved now, i have a .net core 2.2 console application consuming wcf service while it's working fine on development machine but when generated build in CI/CD using win-x64 platform it failed calling service with the same error :

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

@StephenBonikowsky
Copy link
Member

@ehsansajjad465 the System.Private.ServiceModel assembly version 4.1.2.4 was shipped in WCF packages version 4.4.4 which was a .NET Core 2.0 servicing release.

This issue was fixed with the WCF packages version 4.5.0 which was part of the .NET Core 2.1 release.

So you need to update your WCF packages to the 4.5.0 version or newer.
I would recommend at least the latest version released from our 2.1 branch if not our just released 3.0 packages.

@AtanuMandal
Copy link

please use RID. I know win7-64 works. Portable RID will not work

dotnet publish -c Release -r win7-x64 --self-contained true

@kbvishnu
Copy link

The Runtime Identifier (RID) that System.Private.ServiceModel supports on Windows is win7. You can find this by opening up the NuGet package and look at the runtimes folder. The list of supported RIDs for .NET Core is in the runtime.json file. You can see win81-x64 and win10-x64 import win7 (indirectly) so they are S.P.SM compatible RIDs while win-x64 imports win so it's not compatible. The behavior you observed is expected.

How to do this ? Confused on your reply.

@emilbm
Copy link

emilbm commented May 7, 2020

For anyone struggling with this: In the process of upgrading .NET Framework Webjobs to .NET Core 3.1 I faced this issue. I was on 4.4.0 versions of System.ServiceModel packages. Upgrading til 4.7.0 fixed this problem.

@bonasfvck
Copy link

For anyone struggling with this: In the process of upgrading .NET Framework Webjobs to .NET Core 3.1 I faced this issue. I was on 4.4.0 versions of System.ServiceModel packages. Upgrading til 4.7.0 fixed this problem.

@emilbm

I still get this after upgrading to 4.7.0. Im running .NetCore 3.1 already. Error: System.Private.ServiceModel: Configuration files are not supported.

@RicardoJarree
Copy link

This still seems to be happening in .NET 5...

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Adding new functionality requiring adding an API to the public contract.
Projects
None yet
Development

No branches or pull requests