Azure-functions-host: Unable to use System.ServiceModel.Http

Created on 21 May 2018  路  11Comments  路  Source: Azure/azure-functions-host

Investigative information

  • Timestamp: 2018-05-21T16:51:17.390Z
  • Function App version (1.0 or 2.0-beta): 2.0-beta
  • Invocation ID: ed8984d0-1a9a-43c4-959f-3032730b5431
  • Region: eastus

Repro steps

Use a type from System.ServiceModel.Http (e.g. BasicHttpsBinding).

Expected behavior

The type is loaded from the assembly.

Actual behavior

An exception is thrown:

Exception while executing function: FunctionName
Could not load file or assembly 'System.ServiceModel.Http, Version=4.1.2.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
The system cannot find the file specified. Could not load the specified file.

Known workarounds

None

Related information

  • The function works locally using VS 2017 15.7.1 w/ Azure Functions and Web Jobs Tools 15.0.40502.0.
  • The assembly and its dependencies are present on disk.
  • Project file:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <AzureFunctionsVersion>v2</AzureFunctionsVersion>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Dapper" Version="1.50.4" />
    <PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.1.0-preview" />
    <PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="2.0.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.13" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.4.2" />
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  <!-- BEGIN: https://github.com/dotnet/wcf/issues/2824 -->
  <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>
  <!-- END -->
</Project>
2.0 assembly-load

Most helpful comment

The update that is currently rolling out addresses this issue. This is currently being deployed to Azure and the CLI will be available in the next few days

All 11 comments

Can you let us know if it used to work and started showing errors recently?

@pragnagopa

This is the first time I have tried using WCF in an Azure Function.

I updated VS 2017 to 15.7.2 and the CLI Tools to 2.1.0 this morning and the function is no longer working locally (matches the behavior in Azure).

I also tried updating System.ServiceModel.Primitives to match the versions, but I got the same result.

I just managed to get it working by removing the System.ServiceModel.* NuGet packages, adding the DLL's as references (System.ServiceModel, System.ServiceModel.Http, System.ServiceModel.Primitives, System.Private.ServiceModel), and implementing a custom assembly resolver (see https://github.com/dotnet/wcf/issues/2885) to load System.Private.ServiceModel.

@fabiocav - Is this related to assembly loading issue?

Yes, likely, as the current implementation has some restrictions on System.* assemblies.

@EvanMulawski, this is a restriction we'll be relaxing with future updates. Do you have a simple repro you can share on GitHub so we can validate your scenario and make sure that's what is impacting you?

Thank you! Will double check that our upcoming changes resolve the issue with your repro.

We're having the exact same issue.
Waiting for a sensible solution :)

The update that is currently rolling out addresses this issue. This is currently being deployed to Azure and the CLI will be available in the next few days

Seeing same error when added WCF service reference is added to azure function. which version of Nuget package the fix would be?

Thanks again for reporting, for the repro and the patience.

This issue should be resolved with the latest release (2.0.11888). Closing this as resolved, but please let us know if you continue to run into issues.

@fabiocav I'm also facing same issue with latest visual studio version 15.8.4. Can you please let workaround for this

Was this page helpful?
0 / 5 - 0 ratings