【问题标题】:Store SmtpSection in database将 SmtpSection 存储在数据库中
【发布时间】:2014-03-28 05:44:37
【问题描述】:

我想从数据库中而不是从 .config 文件中提取“configuration/system.net/mailSettings/smtp”部分。这可能吗?

我收到以下异常

反映类型“System.Net.Configuration.SmtpSection”时出现错误。

您必须在 System.Configuration.ConfigurationLockCollection 上实现默认访问器,因为它继承自 ICollection。

当我尝试以下代码时

string configFromDb = GetSmtpSectionFromDb();
SmtpSection smtpSettings = null;
using (var stringReader = new StringReader(configFromDb)) {
    using (var xmlReader = new XmlTextReader(stringReader)) {
        var x = new XmlSerializer(typeof(SmtpSection)); // error occurs here!
        smtpSettings = (SmtpSection)x.Deserialize(xmlReader);
    }
}

【问题讨论】:

    标签: c# serialization smtp


    【解决方案1】:

    显然,这是不可能的。我现在不是将 SmtpSection 作为 XML blob 存储在数据库中,而是存储各个字段值。它没有那么“酷”,但它实现了目标。

    【讨论】:

      猜你喜欢
      • 2014-12-05
      • 2011-01-04
      • 2011-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多