As I mentioned earlier, there is currently (.Text 0.95) a known issue with the way .Text implements the MetaWeblog API editpost() method. I discovered this bug while trying to use the w.bloggar desktop publishing tool to edit some posts to my blog (which is obviously run on the .Text engine). After some searching, I quickly found that ScottW had already released a patch for the issued (095_TempFix), but it was only available in assembly form. This meant just copying the new patched dll's over the old ones. This is a problem for anyone who modifies the source code and compiles their own assemblies, which I do. So I decided to find and fix the bug myself (but not before making a quick post to the CS:Blog forums to see if anyone else had done the same).
So I fired up Visual Studio and ran through the code in DEBUG mode and quickly found the problem was an Invalid Type-Cast in the LoadSingleCategoryEntry(IDataReader) method in the Dottext.Framework.Data.DataHelper class:
CategoryEntry entry = (CategoryEntry)LoadSingleEntry(reader);
The problem here is that LoadSingleEntry(IDataReader reader) returns an Entry object, which is inherited by the CategoryEntry object (public class CategoryEntry : Entry). So we are trying to cast a parent object to a child object which causes an Invalid Cast Exception to be thrown. How do we fix this? Well, to me the seemingly logical thing to do would be to get rid of the CategoryEntry class all together and add it's attributes to the Entry class. This would require refactoring at least the Dottext.Framework. While this may be the correct solution, I thought that most users would rather limit the impact of the change and so opted for simply patching the LoadSingleCategoryEntry(IDataReader) method.
The fix is to essentially replace the code in the public static CategoryEntry LoadSingleCategoryEntry(IDataReader) method with the code from the public static Entry LoadSingleEntry(IDataReader reader, bool BuildLinks) method. This was also the path taken by Victor Hadianto as explained in this post. The end result should be:
public static CategoryEntry LoadSingleCategoryEntry(IDataReader reader)
{
CategoryEntry entry = new CategoryEntry();
entry.PostType = (PostType)(int)reader["PostType"];
if(reader["Author"] != DBNull.Value)
{
entry.Author = (string)reader["Author"];
}
if(reader["Email"] != DBNull.Value)
{
entry.Email = (string)reader["Email"];
}
entry.DateCreated = (DateTime)reader["DateAdded"];
entry.DateUpdated = (DateTime)reader["DateUpdated"];
entry.EntryID = (int)reader["ID"];
if(reader["TitleUrl"] != DBNull.Value)
{
entry.TitleUrl = (string)reader["TitleUrl"];
}
if(reader["SourceName"] != DBNull.Value)
{
entry.SourceName = (string)reader["SourceName"];
}
if(reader["SourceUrl"] != DBNull.Value)
{
entry.SourceUrl = (string)reader["SourceUrl"];
}
if(reader["Description"] != DBNull.Value)
{
entry.Description = (string)reader["Description"];
}
if(reader["EntryName"] != DBNull.Value)
{
entry.EntryName = (string)reader["EntryName"];
}
entry.FeedBackCount = (int)reader["FeedBackCount"];
entry.Body = (string)reader["Text"];
entry.Title =(string)reader["Title"];
entry.PostConfig = (PostConfig)((int)reader["PostConfig"]);
entry.ParentID = (int)reader["ParentID"];
SetUrlPattern(entry);
reader.NextResult();
System.Collections.ArrayList al =
new System.Collections.ArrayList();
while(reader.Read())
{
al.Add((string)reader["Title"]);
}
if(al.Count > 0)
{
entry.Categories =
(string[])al.ToArray(typeof(string));
}
return entry;
}
I hope this explaination/fix will help those in the .Text community who have been dealing with this (frustrating) issue. I also want to thank the .Text/CS community for the helping with the fix.