1

We are getting the below error in our application logs. But the error occurs sometimes only.

SmartTargetClaimStore:SmartTargetModule-context_PreRequestHandlerExecute(): Object reference not set to an instance of an object.

Please suggest where to look for the issue, as SmartTarget is a black box for us. TIA.

Update: Code that throws the above error. Please let me know if we need to add an additional check to handle the same.

#region HttpModule

/// <summary>
/// SmartTarget Module
/// </summary>
public class SmartTargetModule : IHttpModule
{
    /// <summary>
    /// Module Intialization
    /// </summary>
    /// <param name="context">Application Context which will be passed to this function by IIS Pipeline</param>
    public void Init(HttpApplication context)
    {
        context.PreRequestHandlerExecute += context_PreRequestHandlerExecute;
    }

    private void context_PreRequestHandlerExecute(object sender, EventArgs e)
    {
        try
        {
            HttpRequest request = HttpContext.Current.Request;
            if (request.Path != null && (request.ServerVariables["SCRIPT_NAME"].Contains(".aspx")))
            {
                NameValueCollection nvc = request.QueryString;
                string[] keys = nvc.AllKeys;
                //Reading all QueryString parameter adding them to AmbientClaimStore
                foreach (string key in keys)
                {
                    string value = nvc[key].ToString();
                    value = HttpUtility.UrlDecode(value);
                    value = value.Contains(":") ? value.Substring(0, value.IndexOf(":")) : value;
                    ClaimStoreManager.AddPredefinedClaimToStore(key.Trim().ToLower(), value.Trim().ToLower());
                }
            }
        }
        catch (Exception ex)
        {
            Log.Message(string.Format("SmartTargetClaimStore:SmartTargetModule-context_PreRequestHandlerExecute(): {0} ", ex.Message), System.Diagnostics.TraceEventType.Error);
            Log.Exception(ex);
        }
    }........

1 Answer 1

2

This looks like a custom-made HTTP Module for IIS made by or for you. In which case you'll need to check with whoever wrote that module.

From the naming alone, it seems to be a module that interacts with the ADF -- so perhaps it's not handling the case where the ADF isn't yet available (or some of the data it needs isn't available).

2
  • Yes, indeed it is the HTTP module, that we found after much digging in. Updated the question with the code block that throws the error. Please let me know if we need to add an additional check to handle the same.
    – guest_2017
    Commented Aug 7, 2017 at 5:25
  • Yes, you should check for null before using objects. As mentioned, you should probably contact whoever wrote that code and tell them about the error to get an update that prevents it. Commented Aug 7, 2017 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.