Pergunta

I have a PageMethod and an AJAX call to that method that passes an array of product SKUs and the number of requested SKUs. It works perfectly fine in DEV(IIS7), but returns a 500 error in PROD(IIS6):

Message: Object reference not set to an instance of an object. 
StackTrace: at ViewProduct.GetInventory(List`1 orderedSkus)
ExceptionType: System.NullReferenceException

Here is the relevant code. If you need specific snippets from my web.config, I can grab those, too, although I don't see anything there that would have any affect on anything.

I have tried to use two different Object definitions in the PageMethod, orderedSkus As Object() and orderedSkus As List(Of Object). Same difference, but also same result... null reference.

AJAX:

    var editedSkus = [];
    function checkInventory() {
        editedSkus.length = 0;
        var textBoxes = $('input:text', '.table-orderMatrix');
        if (formEdited(textBoxes)) {
            var DTO = { 'orderedSkus': editedSkus };
            $.ajax({
                type: "POST",
                url: BasePath + "ViewProduct.aspx/GetInventory",
                data: JSON.stringify(DTO), 
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (msg) {
                    var skus = msg.d;
                    $.each(skus, function () {
                        //do stuff
                    });
                }
            });
        } else {
            // Do other stuff
        }
    }

    var formEdited = function (textBoxes) {
        var edited = 0;
        $.each(textBoxes, function (i) {
            if (this.value > 0) {
                var sku = {};
                sku.skuNumber = $(this).prev().val();
                sku.orderAmount = this.value;
                editedSkus.push(sku);
                edited += 1;
            }
        });
        return edited;
    }

PAGEMETHOD:

    <WebMethod()> _
Public Shared Function GetInventory(orderedSkus As List(Of Object)) As List(Of Object)
    Dim _skus As SKUCollection
    Dim _sku As SKU = Nothing
    Dim warnings As New List(Of Object)
    Dim qty As Integer
    _skus = CurrentStyle.SKUs

    For Each _orderedSku As Object In orderedSkus
        Dim dicValues As New Dictionary(Of String, Object)()
        dicValues = DirectCast(_orderedSku, Dictionary(Of String, Object))
        Dim orderedSkuNumber As String = dicValues("skuNumber").ToString()
        Dim orderAmount As String = CType(dicValues("orderAmount"), Integer)

        Try
            'Stuff
        Catch ex As Exception
            'Health Monitoring
        End Try
    Next

    Return warnings

End Function

EDIT: Adding the "minor detail" that our DEV servers are running IIS7 (where the pagemethod works), while PROD is still under IIS6 (where it does not). I know... don't get me started. Adding this because I feel it may bear significance to the situation.

Foi útil?

Solução

I figured it out. The object was being passed just fine. However, a bit of code was failing in the Try...Catch in PROD that worked fine in DEV (which was completely unrelated to the AJAX call). In turn, instead of providing an appropriate error message (even after adding some error handling in the Catch), I just received the error that the object I sent was null. Weird, but there you go.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top