C# System.Net.Mail.SmtpSender Dispose(bool)的两种不同实现?

C# System.Net.Mail.SmtpSender Dispose(bool)的两种不同实现?,c#,asp.net,.net,decompiling,smtpclient,C#,Asp.net,.net,Decompiling,Smtpclient,谢天谢地,R#7。如果没有他们新的“转到反编译源代码”功能,我将无法描述这个问题 我已经有一段时间使用某个SmtpMailSender实现类了。以下是它所做的几件事: 1.)在开发模式下不发送网络邮件。development web.config如下所示: <smtp deliveryMethod="SpecifiedPickupDirectory"> <specifiedPickupDirectory pickupDirectoryLocation="App_Data

谢天谢地,R#7。如果没有他们新的“转到反编译源代码”功能,我将无法描述这个问题

我已经有一段时间使用某个SmtpMailSender实现类了。以下是它所做的几件事:

1.)在开发模式下不发送网络邮件。development web.config如下所示:

<smtp deliveryMethod="SpecifiedPickupDirectory">
    <specifiedPickupDirectory pickupDirectoryLocation="App_Data/mail" />
</smtp>
<!--<smtp deliveryMethod="Network">
    <network host="smtp.roadrunner.com" />
</smtp>-->
自去年以来,这些都在我的主工作站上工作得很好。不过,我将该项目下载到笔记本电脑上,并一直看到每个
SmtpClient.Send(MailMessage)
都会导致以下异常:

InvalidOperationException: "The SMTP host was not specified."
at System.Net.Mail.SmtpClient.CheckHostAndPort()
at System.Net.Mail.SmtpClient.get_ServicePoint()
at System.Net.Mail.SmtpClient.Dispose(Boolean disposing)
at System.Net.Mail.SmtpClient.Dispose()
at My.ImplementationOf.SmtpMailSender.Send(MailMessage message, Int32 retryCount)
SmtpClient.CheckHostAndPort
引发异常,根据我笔记本电脑上的反编译,当
SmtpClient.Host
属性为null或长度为零时引发异常。我回到我的工作站,发现即使
smtpClient.Host
属性为null,也没有引发此异常

然后我在工作站上为
System.Net.Mail.SmtpClient
使用了R#的小反编译功能,发现这个类有两种不同的实现!非常奇怪,因为对System.dll的引用在两台计算机上都指向
C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.dll
!基本上它们是相同的,但有一个重要的区别:

protected virtual void Dispose(bool disposing)
{
    // the workstation decompilation shows this:
    if (this.transport != null && this.servicePoint != null)
        this.transport.CloseIdleConnections(this.servicePoint);

    // but the laptop decompilation shows this:
    if (transport != null)
        transport.CloseIdleConnections(ServicePoint);
}
这怎么可能有两种不同的实现方式?

更新

两台计算机都显示了Windows 7专业服务包1。我在两台电脑上都运行了Windows Update,两台电脑都告诉我电脑是最新的。我能想到的唯一区别是笔记本电脑的Windows7还没有被激活,我三天前才安装的。我想知道,操作系统的激活会改变框架的System.dll吗

然后我采取了以下步骤:

  • 激活笔记本电脑上的Windows
  • 重新启动
  • 运行Windows Update并发现所有内容仍然是最新的
  • 运行项目场景,发现仍在引发相同的异常

  • IIRC,框架的服务包不会影响程序集版本。我可能错了,但我要检查的第一件事是每台机器的服务包级别


    当然,也有一些修补程序无法像service Pack那样清晰地显示…

    可能是因为一台机器有.NET 4.5,而另一台没有。您是否已将VS2012安装到主工作站上

    此错误已在.NET 4.5中修复:

    安装.NET 4.5会覆盖现有.NET 4.0 DLL之上的新DLL:


    @danludwig:如果你没有在其中一台机器上激活操作系统,如果它没有收到另一台机器上的所有windows更新,我也不会感到惊讶。我已经激活了windows,检查了更新,并更新了我的问题。你解决了
    InvalidoOperationException
    的问题了吗?我对
    指定的ICKUPdirectory
    交付方法也有同样的问题。@TN.是的,这个问题很容易解决。只需确保在
    smtp
    部分中还有一个
    节点以及
    指定的ICKUPdirectory
    节点。我从未对解决方案感兴趣,我感兴趣的是找出为什么有2个SmtpClient实现+1个Thx。我在所有Win 7 x86计算机上都有以下实现(带有最新更新):if(disposing&&!this.disposed){if(this.InCall&&!this.cancelled){this.cancelled=true;this.Abort();}if(this.transport!=null){this.transport.CloseIdleConnections(this.ServicePoint);}if(this.timer!=null){this.timer.Dispose();}this.disposed=true;}^使用ILSpy.Hmm反映,但“旧”版本似乎正常。“新”版本已损坏:(
    protected virtual void Dispose(bool disposing)
    {
        // the workstation decompilation shows this:
        if (this.transport != null && this.servicePoint != null)
            this.transport.CloseIdleConnections(this.servicePoint);
    
        // but the laptop decompilation shows this:
        if (transport != null)
            transport.CloseIdleConnections(ServicePoint);
    }