System.ServiceModel not found in .NET Core project

I have a .NET Core xUnit project. I try to call the WCF service from it, but I get the following exception:

System.InvalidOperationException occurred
  HResult=0x80131509
  Message=An error occurred while loading attribute 'ServiceContractAttribute' on type 'IMyContract'.  Please see InnerException for more details.

Inner Exception 1:
FileNotFoundException: Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

It works with a Framework 4.7 project with the same Nuget package System.ServiceModel.Http.4.3.0.

+14
source share
3 answers

Microsoft has already made available the appropriate assemblies in the form of packages on NuGet.

System.ServiceModel.Primitives - the base package; add others, if necessary, to your project.

enter image description here

-eleven
source

If you are using .NET Standard 2.0(which I tested), you can install compatible packages NuGet.

System.ServiceModel.Primitives ( v4.4.0).

System.ServiceModel.Http.

+38

- Microsoft WCF SvcUtil.exe .NET Standard . , ServiceModel, .

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.3.0" />
    <PackageReference Include="System.ServiceModel.Http" Version="4.3.0" />
    <PackageReference Include="System.ServiceModel.NetTcp" Version="4.3.0" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.3.0" />
    <PackageReference Include="System.Xml.XmlSerializer" Version="4.3.0" />
  </ItemGroup>
</Project>

, .NET Core.

+12
source

Source: https://habr.com/ru/post/1683161/


All Articles