Updating existent post on the new 1.4.5

Topics: ASP.NET 2.0, Business Logic Layer
Aug 2, 2008 at 10:07 AM
Hy all.
I just upgraded to the new version, and I got this error when updating an existent post. Fortunately the changes are stored, but I get this error for all the post I had in the db. What's the matter? I didn't have the time to look into the code yet.



 Value cannot be null.
Parameter name: input
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: input

Source Error:

Line 157:        private List<IPublishable> SearchForPosts()
Line 158:        {
Line 159:            return Search.FindRelatedItems(this.Item);
Line 160:        }
Line 161:    }


Source File: c:\_WebSites\blog.teammatelabs.com\www\App_Code\Controls\RelatedPosts.cs    Line: 159

Stack Trace:

[ArgumentNullException: Value cannot be null.
Parameter name: input]
   System.Text.RegularExpressions.Regex.Matches(String input) +2145639
   System.Text.RegularExpressions.Regex.Matches(String input, String pattern) +40
   BlogEngine.Core.Search.BuildResultSet(String searchTerm, Boolean includeComments) in C:\Documents and Settings\Mads Kristensen\Dokumenter\Visual Studio 2005\Projects\BlogEngine.NET\DotNetSlave.BusinessLogic\Search.cs:161
   BlogEngine.Core.Search.Hits(String searchTerm, Boolean includeComments) in C:\Documents and Settings\Mads Kristensen\Dokumenter\Visual Studio 2005\Projects\BlogEngine.NET\DotNetSlave.BusinessLogic\Search.cs:94
   BlogEngine.Core.Search.FindRelatedItems(IPublishable post) in C:\Documents and Settings\Mads Kristensen\Dokumenter\Visual Studio 2005\Projects\BlogEngine.NET\DotNetSlave.BusinessLogic\Search.cs:137
   Controls.RelatedPosts.SearchForPosts() in c:\_WebSites\blog.teammatelabs.com\www\App_Code\Controls\RelatedPosts.cs:159
   Controls.RelatedPosts.RenderControl(HtmlTextWriter writer) in c:\_WebSites\blog.teammatelabs.com\www\App_Code\Controls\RelatedPosts.cs:99
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
   System.Web.UI.Control.Render(HtmlTextWriter writer) +7
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
   ASP.themes_darkblog_site_master.__Renderform1(HtmlTextWriter __w, Control parameterContainer) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\03833c10\649aebb0\App_Web_ciqghxfs.0.cs:0
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +98
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
   System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +59
   System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +68
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
   System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +37
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
   System.Web.UI.Control.Render(HtmlTextWriter writer) +7
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
   System.Web.UI.Page.Render(HtmlTextWriter writer) +26
   BlogEngine.Core.Web.Controls.BlogBasePage.Render(HtmlTextWriter writer) in C:\Documents and Settings\Mads Kristensen\Dokumenter\Visual Studio 2005\Projects\BlogEngine.NET\DotNetSlave.BusinessLogic\Web\Controls\BlogBasePage.cs:329
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2558

Aug 2, 2008 at 9:14 PM
Its kinda of hard to tell with out stepping through the code, but it looks like the real error is getting thrown when the regular expression tries to pull matches from the entry.content.(i think if the title was the null object offender, an exception would be thrown earlier in the stack trace.

I am not familiar with 1.4.5 yet, but has something changed with with where the content is pulled from the XML file for an entry?  The other possibility is the Regex string is not being initialized properly...

Aug 4, 2008 at 7:24 AM
Sorry to all, I wasn't able to post the solution I found on saturday. Since I hadn't the time to check deep into the code, I did a small experiment. Create a new db instance and using the blogml function I regenerate the cotent. Certainly I also had to change all the setting etc, but in this way now all works fine.
So I suspect that migrating using old db cannot work due to something missing into the updating script. I'm not sure about this, obviously.
Sep 20, 2008 at 11:47 AM
Edited Sep 20, 2008 at 11:52 AM

I have just done a SQL migration from my Community Server database and I hit this problem. After reflecting the Core assembly, the problem is occuring because the be_Posts.Description and be_Pages.Description columns are nullable, but the code in BlogEngine.Core.Search.BuildResultSet contains this line of code:

int descriptionMatches = Regex.Matches(entry.Item.Description, regex).Count;

If the value in the database is null, then this Regex throws a NullArgumentException. I ran the following update:
 
update be_pages
set description = '' where description is null
 
update be_posts
set description = '' where description is null

I then saved web.config for force an unload of the application. After loading the site again, it all seems to work.

This is a bug one way or the other. Either the column needs to not allow null values, or this code needs to be more defensive.

Sep 20, 2008 at 11:51 AM
I have created an issue to address this bug - http://www.codeplex.com/blogengine/WorkItem/View.aspx?WorkItemId=7640