1

Resolved

Threading Issues

description

Hi.

I'm working on a new extension and after upgrading from an older blog installation to the current codebase I got an very annoying error.

It was a System.NullReferenceException by the Category-typeinitializer. At first I've just looked into the constructors of Category and found nothing special.
After some testing I saw the static field _Folder which calls Server.MapPath..

The problem is, that there is no HttpContext when my extension is working! So the call of HttpContext.Current.Server.MapPath fails.

To solve my problem I replaced the _Folder field by this property:

internal static string _Folder
{
get
{
    string p = BlogSettings.Instance.StorageLocation.Replace("~/", "");
    return System.IO.Path.Combine(System.Web.HttpRuntime.AppDomainAppPath, p);
}
}

Oh and the SendPings extension needs some change too:

if (!HttpContext.Current.Request.IsLocal && item.IsVisible)
needs to be replaced by
if ((HttpContext.Current == null || !HttpContext.Current.Request.IsLocal) && item.IsVisible)




Yours, Alex

comments

madskristensen wrote Dec 17, 2007 at 3:46 PM

Can you please upload your extension so I can see what might be causing this. I've never had that problem before.

aschuc wrote Dec 17, 2007 at 3:54 PM

At the moment I do not want to upload it, but I can describe it to you.

When the extension is created it starts a new background thread which checks every n-minutes for new mails,.. so it's a mail 2 blog extension which runs in the background. So the chance is high that there is no HttpContext when a new Post is created.

aschuc wrote Dec 23, 2007 at 10:22 AM

The _Folder property in Category.cs is still using HttpContext.Current. So when there is some dataacess when no HttpContext is available it would produce an error.

Thanks.. :)