将JSON对象传递给PageMethod在DEV中工作,而不是PROD

时间:2012-10-31 14:54:46

标签: asp.net ajax json nullreferenceexception pagemethods

我有一个PageMethod和一个对该方法的AJAX调用,它传递了一系列产品SKU和请求的SKU数量。它在DEV(IIS7)中工作得很好,但在PROD(IIS6)中返回500错误:

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

这是相关代码。如果您需要我的web.config中的特定代码段,我也可以抓住它们,虽然我没有看到任何会对任何事情产生影响的内容。

我试图在PageMethod,orderedSkus As Object()和orderedSkus As List(Of Object)中使用两个不同的Object定义。相同的差异,但同样的结果......空引用。

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

编辑:添加我们的DEV服务器运行IIS7(页面方法有效)的“次要细节”,而PROD仍然在IIS6下(它没有)。我知道......不要让我开始。加上这个因为我觉得它可能对这种情况有意义。

1 个答案:

答案 0 :(得分:1)

我明白了。对象被传递得很好。然而,一些代码在PROD中的Try ... Catch失败,在DEV中运行良好(这与AJAX调用完全无关)。反过来,我没有提供适当的错误消息(即使在Catch中添加了一些错误处理后),我只是收到了我发送的对象为空的错误。很奇怪,但你去了。