神秘的 "Couldn't not load file or assembly 'System.ServiceModel, Version=4.0.0.0..." 错误

The mysterious "Couldn't not load file or assembly 'System.ServiceModel, Version=4.0.0.0..." error

场景:我有一个 WCF 端点 (endpoint Manufacturing) 连接另一个 WCF 端点 (endpoint DataAPIClient) 作为 ConnectedService。 A 中实体的构造函数实例化 "client"(见下文)。在所有这些之上,我有一个 xUnit 测试项目测试 A.

// Manufacturing constructor
public Manufacturing() {
  client = new DataAPIClient();
}

// 在xUnit项目中实例化 制造端点 = new Manufacturing();

问题:当测试项目尝试实例化 Manufacturing 时发生了一些变化(我不知道是什么)。我收到此错误:

Message: System.IO.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.

我已经验证了两个端点中的 System.ServiceModel.dll。 DataAPIClient 有 4.0.30319,制造有 4.0.0.0.

P.S。我确实更改了 Manufacturing 项目的名称...不确定是否是这个原因造成的,但我认为它可能值得一提。

非常感谢任何帮助...我一直在谷歌搜索但一无所获。

根据 howcheng 的建议,我注意到由于我使用的是 xUnit 测试项目 (.NET Core),所以我无法(或者我可能只是不知道如何)添加对 System.ServiceModel.dll 的任何引用。因此,我创建了一个单元测试项目 (.NET Framework) 并添加了 xUnit Nugets 和 System.ServiceModel.dll 程序集。错误消失了。