【发布时间】: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