首页 > 解决方案 > 构造函数中的 SmtpResponse 异常

问题描述

我正在将我们的垃圾邮件过滤器从 Exchange 2013 更新到 2019。我的传输代理引用了这两个 DLL:

Microsoft.Exchange.Data.Common.dll
Microsoft.Exchange.Data.Transport.dll

当我将这些 DLL 的 2013 版本替换为 Exchange 2019 中的新版本时,以下两行代码都会生成异常:

// Exchange 2019 syntax
SmtpResponse smtpResponse = SmtpResponse.Create("550", "5.7.1", "A single string");


// Exchange 2013 syntax (deprecated under 2019, but still compiles)
SmtpResponse smtpResponse = new SmtpResponse("550", "5.7.1", "A single string");

异常消息是:

Der Typeninitialisierer für "Microsoft.Exchange.Data.Transport.Smtp.SmtpResponse" hat eine Ausnahme verursacht."* ... 的类型初始化程序已生成异常。

即使是这条简单的线也会导致异常:

SmtpResponse smtpResponse = new SmtpResponse();

任何想法为什么 SmtpResponse 的构造函数会抛出此异常?在 Exchange 2013 上,此代码多年来一直完美运行。

标签: exchange-server

解决方案


好的,在 Exchange Server 2019 上,Microsoft.Exchange.Data.Transport.dll有一个新的依赖项Microsoft.Exchange.Diagnostics.dll. 此 DLL 不像其他 DLL 那样位于 Exchange Server 的 Public 文件夹中,而是位于 bin 文件夹中。

将 Microsoft.Exchange.Diagnostics.dll 复制到我的本地 bin 文件夹解决了这个问题。


推荐阅读