我有一个 .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 是基础包;如有必要,将其他人添加到您的项目中。
更新(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/