c# - 在 .NET Core 项目中找不到 System.ServiceModel

标签 c# .net wcf .net-core

我有一个 .NET Core xUnit 项目。我正在尝试从中调用 WCF 服务,但出现以下异常:

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.

它适用于具有相同 Nuget 包 System.ServiceModel.Http.4.3.0 的 Framework 4.7 项目。

最佳答案

Microsoft 现已在 NuGet 上以包的形式提供相关程序集。

System.ServiceModel.Primitives 是基础包;如有必要,将其他人添加到您的项目中。

enter image description here

更新(2022 年 4 月 28 日):

WCF 已通过名为 CoreWCF 的官方库部分移植到 .NET 5+:https://devblogs.microsoft.com/dotnet/corewcf-v1-released/

关于c# - 在 .NET Core 项目中找不到 System.ServiceModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45545013/

相关文章:

c# - 在 .Net 中使用 ObjectCache 缓存对象并过期

c# - 只设置单个 View 的 Culture,而不是整个程序

c# - 在 Windows 中运行 dotnet watch 时出错

.net - 如何用鼠标中键关闭TabControlEx选项卡?

c# - 带有 xmlSerializer 的 UWP - System.InvalidOperationException : Unable to generate a temporary class (result=1) compile error

c# - 将值传递给 ObjectParameter 变量

c#存储库模式 : One repository per subclass?

C# 无法反序列化 DataTable

c# - 更改图形设置调用 `LoadContent`

c# - .Net Remoting 不使用.Net Remoting?