About the author

Steven HarmanSteven Harman is a passionate developer who believes that writing great software isn't just a job, its a craft.

ASP.NET MVP

For recent posts and more about me, scroll to the bottom.

Subscribe

  • Subscribe to my feed. via RSS
  • Subscribe via email via email

News

devLINK Technical Conference

Jobs

Badges

  • Subtext Project
  • Support Subtext
  • HiddenNetwork.com Banner

.Text's MetaWeblog API - Edit Post Error...

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.

What others are saying.

# Edit Post in .Text
Gravatar Dan Miser
Jan 11, 2005
# Implementing rel =
Gravatar Kevin Harder
Jan 19, 2005
# Debugging a .NET WebApp in VS.NET
Gravatar StevenHarman.net
Feb 12, 2005
I've blogged before about debugging dotText in Visual Studio, and recently I've gotten a few emails asking for some help with getting the VS.NET Debugger working. I know that it took some time to get the debugger working correctly with dotText, so I thought I'd put together a little How-To. I'm pretty sure that these instructions will work for ASP.NET web applications, but I'll be using dotText v0.95 for this Guide.
# Debugging goodness from Steve Harman
Gravatar Dave Burke's Blog
Feb 12, 2005
# Re: And The Winner Is: .Text!
Gravatar RGabostyle.com
Feb 14, 2005
# Updated my engine.
# Updated my Engine
Gravatar Blue Phoenix
Feb 15, 2005
# Updated my engine.
Gravatar Blue Phoenix
Feb 15, 2005
# re: The Current Status of .Text...
Gravatar StevenHarman.net
Mar 22, 2005

thanks for the feedback and the heads up on CS 1.0! I'm still using dotText 0.95 (w/some modifications I've made), but I've played around with the CS 1.0 source a little. For now I'll probably be sticking with 0.95 until I become more familiar w/ CS and some of the bugs get worked out (maybe version 1.1 or 1.2). I have actually made a few fixes/mods to the 0.95 codeset, and I've been meaning to put a list of the changes together on my blog. I also want to include the source for the changes I've made so the rest of the dotText community can use them... hopefully I'll get to that soon! For now, here's a list of fixes/mods I've made:
# Debugging a .NET WebApp in VS.NET
Gravatar StevenHarman.net
Apr 29, 2005
# re: .Text's MetaWeblog API - Edit Post Error...
Gravatar vern
Jul 01, 2005
If you are interested in staying with dotText, you should check out subText, a fork of the .Text codebase.
http://subtextproject.com
# Nice colors! Good job. thankyou.
Gravatar
Jul 02, 2006
Nice colors! Good job. thankyou.
# Open Source Recruiting Is Fundamental
Gravatar Haacked
Jul 31, 2006
Open Source Recruiting Is Fundamental
# You are not right, Mate, I really think so
Gravatar Anon
Sep 08, 2006
You are not right, Mate, I really think so
Comments have been closed on this topic.