我正在使用BlogEngine为我工作的公司开发一个自定义博客。在此之前,一切似乎工作正常,但我现在每次尝试运行整个项目时都会抛出异常。
类型' System.ArgumentException'的例外情况发生在 mscorlib.dll但未在用户代码中处理附加信息: 项目已添加。键入字典:' displayname'键 被添加:' displayname'
这是抛出异常的代码片段:
public override AuthorProfile SelectProfile(string id)
{
var dic = new StringDictionary();
var profile = new AuthorProfile(id);
// Retrieve Profile data from Db
using (var conn = this.CreateConnection())
{
if (conn.HasConnection)
{
if (Blog.CurrentInstance.IsSiteAggregation)
{
using (var cmd = conn.CreateTextCommand($"SELECT SettingName, SettingValue FROM {tablePrefix}Profiles WHERE UserName = {parmPrefix}name"))
{
cmd.Parameters.Add(conn.CreateParameter(FormatParamName("name"), id));
using (var rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
dic.Add(rdr.GetString(0), rdr.GetString(1));
}
}
}
}
else
{
using (var cmd = conn.CreateTextCommand(string.Format("SELECT SettingName, SettingValue FROM {0}Profiles WHERE BlogID = {1}blogid AND UserName = {1}name", this.tablePrefix, this.parmPrefix)))
{
cmd.Parameters.Add(conn.CreateParameter(FormatParamName("blogid"), Blog.CurrentInstance.Id.ToString()));
cmd.Parameters.Add(conn.CreateParameter(FormatParamName("name"), id));
using (var rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
dic.Add(rdr.GetString(0), rdr.GetString(1));**[* EXCEPTION IS THROWN AT THIS LINE]**
}
}
}
}
}
}
请问,我该如何解决这个问题?
答案 0 :(得分:0)
在if
dic.Add()
子句
if (!dic.ConatinsKey(rdr.GetString(0)))