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

Could not load file or assembly 'System.Private.ServiceModel, Version=4.1.2.2 #2824

Closed
ssashok10 opened this issue May 4, 2018 · 39 comments
Closed
Assignees

Comments

@ssashok10
Copy link

I am using Azure Function (C#) which is calling a .NET standard library to call an external WCF service and I am getting the below error. I am not sure what exactly happening inside the Function call.

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

Here are the platform information,
Microsoft.NET.Sdk.Functions (1.0.13)
.NET Standard Library 2.0
System.ServiceModel.Primities 4.4.2
System.ServiceModel.Http 4.4.2

There is no reference to 4.1.2.2 DLL from any of my VS projects

@Lxiamail Lxiamail added this to the S135 milestone May 4, 2018
@Lxiamail Lxiamail self-assigned this May 4, 2018
@zhenlan
Copy link
Member

zhenlan commented May 7, 2018

@ssashok10 thanks for reporting the issue. I can reproduce it. Here is just a quick workaround to unblock you. We will need to take a further look of the issue.

First, copy file %USERPROFILE%\.nuget\packages\system.private.servicemodel\4.4.2\runtimes\unix\lib\netstandard2.0\system.private.servicemodel.dll to the root of your function app. If file is not found, you can download the nuget package from nuget.org.

Then, copy/paste below to your project's .csproj file. It will include S.P.SM.dll for build and publish.

  <ItemGroup>
    <None Update="System.Private.ServiceModel.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
  <Target Name="CopySPSM" BeforeTargets="Build">
    <Copy SourceFiles="System.Private.ServiceModel.dll" DestinationFolder="$(OutputPath)\bin" />
  </Target>

@ssashok10
Copy link
Author

The work around worked well. Thanks for looking into it.

@zhenlan
Copy link
Member

zhenlan commented May 7, 2018

Thanks for the confirmation @ssashok10.

Reactivating the issue to track root-cause investigation.

@zhenlan zhenlan reopened this May 7, 2018
@zhenlan zhenlan added the bug This is a product bug. label May 8, 2018
@Lxiamail Lxiamail modified the milestones: S135, S136 May 18, 2018
@mgirard1mtx
Copy link

We are currently reproducing this on our side too.

The work around we use is to copy the "runtimes" folder beside our application (obtained by doing a dotnet publish).

The contents of runtimes is:

$find runtimes/
runtimes/
runtimes/unix
runtimes/unix/lib
runtimes/unix/lib/netcoreapp2.0
runtimes/unix/lib/netcoreapp2.0/System.Security.Principal.Windows.dll
runtimes/unix/lib/netstandard2.0
runtimes/unix/lib/netstandard2.0/System.Private.ServiceModel.dll
runtimes/win
runtimes/win/lib
runtimes/win/lib/netcoreapp2.0
runtimes/win/lib/netcoreapp2.0/System.Security.Principal.Windows.dll
runtimes/win/lib/netcoreapp2.0/System.Security.AccessControl.dll
runtimes/win/lib/netstandard2.0
runtimes/win/lib/netstandard2.0/System.Security.Cryptography.ProtectedData.dll
runtimes/win/lib/netstandard2.0/System.Private.ServiceModel.dll

@hansmbakker
Copy link

I still have this issue in VS 15.8 Preview 5 when generating a wcf connected service reference in a .net standard 2-based Azure Functions project.

@rhythmnewt
Copy link

Any idea when a permanent fix will be available? This is quite a hassle to deal with both debugging locally and in our devops pipeline.

@rhythmnewt
Copy link

Anyone else dealing with this issue: to make life slightly better add the System.Private.ServiceModel nuget to the project then only add this section to the .csproj. No manual copy of the offending assembly is required to the root folder (may even work on your build server but YMMV).

Note that the version specified in the path is the current version of the assembly, you'll need to manually sync it with the referenced nuget package.

  <Target Name="CopySPSM" 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>

@corveen
Copy link

corveen commented Sep 26, 2018

Any idea when a permanent fix will be available? This is quite a hassle to deal with both debugging locally and in our devops pipeline.

I think they marked it to be fixed in .NET Core 3.0 :)

@rhythmnewt
Copy link

Well, 2019 is only a stone's throw away :) Will have to keep the workaround for now.

@corveen
Copy link

corveen commented Sep 26, 2018

Do you have a workaround that works for continuous deployment to Azure, or even basic publish from Visual Studio? I can make it work locally , but nothing more than that,

@rhythmnewt
Copy link

What's not working for VS publish? I tested a publish to a local folder and all the files got copied over.

@IGx89
Copy link

IGx89 commented Sep 27, 2018

zhenlan's workaround works great for us both locally and on our build server (msbuild publish using the 15.7 build tools) as well, using the v2 runtime.

@Lxiamail
Copy link
Member

Lxiamail commented Oct 2, 2018

Looks like it is Azure function issue. When building Azure function project, system.private.servicemodel.dll should be copied to "$(OutputPath)\bin" folder along with other project dependencies. Opened issue
#Azure/Azure-Functions#974 to track it in Azure function repo.

@colinbowern
Copy link

colinbowern commented Jan 7, 2019

I'm using this snippet with an .NET Core 2.0 class library app targeting AWS Lambda being build under Ubuntu (WSL):

  <ItemGroup>
    <None Include="$(NuGetPackageRoot)system.private.servicemodel\4.5.3\runtimes\unix\lib\netstandard2.0\System.Private.ServiceModel.dll" CopyToPublishDirectory="Always" CopyToOutputDirectory="Always" />
  </ItemGroup>

This issue doesn't appear to be specific to Azure Functions projects.

@ismailhozza
Copy link

I am also having this issue. The workaround seems to be working, but can someone explain to me what is the root cause? Thanks

@Lxiamail
Copy link
Member

Lxiamail commented Jan 9, 2019

@ismailhozza Please look at #Azure/Azure-Functions#974 for explaination

@Lxiamail
Copy link
Member

Lxiamail commented Jan 9, 2019

@colinbowern Yes, it may not be specific to Azure Functions projects, but the root cause is the same.

@ceduard0
Copy link

I am using Azure Function (C#) which is calling a .NET standard library to call an external WCF service and I am getting the below error. I am not sure what exactly happening inside the Function call.

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

Here are the platform information,
Microsoft.NET.Sdk.Functions (1.0.13)
.NET Standard Library 2.0
System.ServiceModel.Primities 4.4.2
System.ServiceModel.Http 4.4.2

There is no reference to 4.1.2.2 DLL from any of my VS projects

Hello,
I solved this issue in the publish settings , after that go to runtime target option and changed to"Portable".

This solved the issue.

@vertonghenb
Copy link

Issue is still present in ASP.NET Core 3.0 preview 3 with a publish as a Web App.

@Lxiamail
Copy link
Member

@vertonghenb The issue was resulted by Azure/azure-functions-host#3568, did you followed the guidance stated in that resolution? If so, please report the issue under Azure/azure-functions-host#3568.

@mahl
Copy link

mahl commented Apr 3, 2019

I'm also seeing this issue. Will it be fixed?

@emjion
Copy link

emjion commented Jun 4, 2019

have still an issue when I'm using a WCF service in an asp.net core 2.2. It just occurs in IIS environment. Even in case that I start it via command line, I'm faced with the following 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.
Can you please provide the missing assembly as a workaround? Or give me a hint?

@emjion
Copy link

emjion commented Jun 5, 2019

Solved issue by increasing version of System.ServiceModel to 4.5.3

@SaebAmini
Copy link

SaebAmini commented Jul 24, 2019

The only workaround that did the job for me was copying the DLL from the runtime folder, to the bin folder, after build and publish events, by adding this to my Azure Function app csproj, I noticed the DLL is copied there, but the function host doesn't know how to find it:

<Target Name="FixForDotnetWcfIssueBuild" BeforeTargets="PostBuildEvent">
  <Copy SourceFiles="$(OutputPath)bin\runtimes\win\lib\netstandard2.0\System.Private.ServiceModel.dll" DestinationFolder="$(OutputPath)bin" />
</Target>
<Target Name="FixForDotnetWcfIssuePublish" AfterTargets="AfterPublish">
  <Copy SourceFiles="$(PublishDir)bin\runtimes\win\lib\netstandard2.0\System.Private.ServiceModel.dll" DestinationFolder="$(PublishDir)bin" />
</Target>

@MasiumDev
Copy link

MasiumDev commented Aug 28, 2019

@ssashok10 thanks for reporting the issue. I can reproduce it. Here is just a quick workaround to unblock you. We will need to take a further look of the issue.

First, copy file %USERPROFILE%\.nuget\packages\system.private.servicemodel\4.4.2\runtimes\unix\lib\netstandard2.0\system.private.servicemodel.dll to the root of your function app. If file is not found, you can download the nuget package from nuget.org.

Then, copy/paste below to your project's .csproj file. It will include S.P.SM.dll for build and publish.

  <ItemGroup>
    <None Update="System.Private.ServiceModel.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
  <Target Name="CopySPSM" BeforeTargets="Build">
    <Copy SourceFiles="System.Private.ServiceModel.dll" DestinationFolder="$(OutputPath)\bin" />
  </Target>

use Install-Package System.Private.ServiceModel command on the project, its work.

@davlinski
Copy link

davlinski commented Sep 18, 2019

For me, it wasn't enough just to copy this assembly to the output path; the publish folder was the silver bullet in my case:

  <Target Name="CopySPSM" BeforeTargets="Build">
    <Copy SourceFiles="$(USERPROFILE)\.nuget\packages\system.private.servicemodel\4.5.1\runtimes\win\lib\netstandard2.0\System.Private.ServiceModel.dll" DestinationFolder="$(OutputPath)\publish\bin" />
    <Copy SourceFiles="$(USERPROFILE)\.nuget\packages\system.private.servicemodel\4.5.1\runtimes\win\lib\netstandard2.0\System.Private.ServiceModel.dll" DestinationFolder="$(OutputPath)\bin" />
  </Target>

Since I was (am) publishing directly to Azure Functions from Visual Studio Code, this assembly needs to be present in the publish folder as well. Anyway, this is what finally unblocked my project and allowed my function to fly free!!

@SaebAmini
Copy link

Updating to 4.6.0 solved this issue for me and I could remove the hack.

@soonu-kedari
Copy link

Update to 4.6.0 and add code
AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler", false);
in Startup.cs

Please refer

@DevDrake
Copy link

I have similar issue with MetadataLoadContext with dotnet core 3.
I am Loading .Net framweowrk/netstandard libraries trought it.
Basically the project works in "debug", but in "release" it is reporting missing System.Private.ServiceModel.
The workaround is not very convenient. Because providing the dll pulls requirement for other dlls in the netstandard version to recognize base types.

@ADefWebserver
Copy link

I got this with a Blazor 3.1 app. Works fine locally, but, when deployed to Azure I get:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Private.ServiceModel

To fix it, in the Publish Profile, in Visual Studio, I changed the Target runtime from win-x86 to portable

@stevenlupo
Copy link

stevenlupo commented Nov 27, 2020

I'm getting this now with .NET Core 3.1. Like someone said above, upgrading to 4.6 worked.

@Vimal-Asir
Copy link

Vimal-Asir commented Dec 21, 2020

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

hai , iam doing one kyc application , here i have connected with web services of ndml registration .my project in developmennt its working fine . when i tried to access web services after deployment iam facing mentioned above issue.

Framework : .NET Core 3.1

Iam installed Version="4.3.3" but why its referring Version=4.1.1.3 of System.Private.ServiceModel
I am not sure what exactly happening inside the Function call.

Please give me some solution for this issue

@andre-wells
Copy link

Also seeing this in net5. Runs fine in Visual Studio but if I try to publish my webapp to desk and execute the exe I get this:

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'

@Premier-Solutions
Copy link

Also seeing this in net5. Runs fine in Visual Studio but if I try to publish my webapp to desk and execute the exe I get this:

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'

Same issue here.
Runs fine locally.
But when deploying to AWS Elastic beanstalk, throws the same exception.

Did you find any solution?

1 similar comment
@Premier-Solutions
Copy link

Also seeing this in net5. Runs fine in Visual Studio but if I try to publish my webapp to desk and execute the exe I get this:

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'

Same issue here.
Runs fine locally.
But when deploying to AWS Elastic beanstalk, throws the same exception.

Did you find any solution?

@z7g
Copy link

z7g commented Nov 20, 2024

I install System.Private.ServiceModel in nuget,the problem is resolved.

@kinguru
Copy link

kinguru commented Nov 22, 2024

I've the issue also. But nuget lib installation do not solve. The lib is not in the publish folder when published. And crashes with the known exception.

@z7g
Copy link

z7g commented Nov 23, 2024

I search the latest version in the nuget org source and install the newest version.my sdk is .NET 8.

@z7g
Copy link

z7g commented Nov 23, 2024

I've the issue also. But nuget lib installation do not solve. The lib is not in the publish folder when published. And crashes with the known exception.

the lib may be in some sub directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests