0

嗯,eBay SDK 有很多不错的示例选择,但是它们已经过时,大多数都无法使用,您可以NullReferenceException在线获得。我是一名 Windows 编码员大约 5 年(5 年前,我只知道足够的 .Net 来让我通过。我主要开发大型基于 Web 的应用程序)

这个特定的应用程序以给定的时间间隔通过 Windows 服务轮询 eBay API,并使用待发货的待发货订单更新 SQL 数据库。这不是必需的,因为此代码是直截了当的,而不是问题所在。

这是有问题的旧 VB .Net 代码行,请记住 intelliSense 将代码显示为在代码视图中有效。

 Dim Transactions As TransactionTypeCollection 
 Transactions = apiCall.GetSellerTransactions("1/1/2012 5:51:09 AM", "1/30/2012 5:51:09 AM")

运行第二行代码时,我收到此错误:

NullReferenceException was unhandled
Object reference not set to an instance of an object.

Visual Studio 提供了一些疑难解答提示,例如在调用之前确保设置的对象不为 NULL(Nothing),以及在调用方法之前使用 New 关键字创建对象的新实例。我尝试了这些方法的所有组合,例如:

Dim Transactions As New Transaction TypeCollection

或者在定义交易之后,

Transactions = New apicall.getSellerTransaction()
    'didnt think this would work but I've tried everything

这些没有帮助,第一个也没有产生任何额外的错误(第二个,我假设让你知道 getSellerTransaction() 不是构造函数)。

有什么建议么?

感谢您阅读长篇文章,只是想尽可能彻底。顺便说一句,我正在使用来自 developer.ebay.com 的最新 eBay .NET SDK 尝试执行 getSellerTransaction。我在生成令牌时遇到了类似的问题,但修复方法不同。我认为这是一个语法错误。谢谢你的帮助。如果您需要更多详细信息,我将在这里回答任何问题。

-麦克风

附加代码

我正在使用一个简单的流编写器从事务中捕获足够的数据,以便我知道它们可以工作(当我克服这个错误时,待处理的订单将被填充到一个 sql 数据源中)。这也是一个 Windows 服务(因此theServiceWorkerThread)此外,eBay SDK 中提供的 .Net 演示应用程序(至少 GetSellerTransactions 失败,错误代码相同,位置相同)

 Private Sub ServiceWorkerThread(ByVal state As Object)
    ' Periodically check if the service is stopping.
    Do While Not Me.stopping
        ' Perform main service function here...
        Dim apiCall As GetSellerTransactionsCall = New GetSellerTransactionsCall(apiContext)

        Dim transactions As New TransactionTypeCollection

        'the line below causes the exception
        transactions = apiCall.GetSellerTransactions("1/1/2012 5:51:09 AM", "1/30/2012 5:51:09 AM")
        Dim trans As New TransactionType
        For Each trans In transactions

            Me.sysLog.WriteEntry("ItemId: " & trans.Item.ItemID)
            Me.sysLog.WriteEntry("TransId: " & trans.TransactionID)
            Me.sysLog.WriteEntry("TransPrice: " & trans.TransactionPrice.Value.ToString())
            Me.sysLog.WriteEntry("AmtPaid: " & trans.AmountPaid.Value.ToString())
            Me.sysLog.WriteEntry("qtyPurchased: " & trans.QuantityPurchased.ToString())
            Me.sysLog.WriteEntry("buyUserId; " & trans.Buyer.UserID)

        Next trans

        Thread.Sleep(60000)  ' Simulate some lengthy operations.
    Loop

    ' Signal the stopped event.
    Me.stoppedEvent.Set()
End Sub

<summary>
    Populate eBay SDK ApiContext instance with data from application configuration file
</summary>
<returns>ApiContext instance</returns>
<remarks></remarks>

 Private Function GetApiContext() As ApiContext

    'apiContext is a singleton
    'to  avoid duplicate configuration reading
    If (apiContext IsNot Nothing) Then
        Return apiContext
    Else
        apiContext = New ApiContext

        'set Api Server Url
        apiContext.SoapApiServerUrl = AppSettings("SopApiServerUrl")

        'declare new ApiCredential
        Dim apiCredential As ApiCredential = New ApiCredential
        'set Applcation settings (not needed with a User Token)
        apiCredential.ApiAccount.Application = AppSettings("AppId")
        apiCredential.ApiAccount.Certificate = AppSettings("AppCert")
        apiCredential.ApiAccount.Developer = AppSettings("DevId")

        'set our User Token
        apiCredential.eBayToken = AppSettings("UserToken")

        apiContext.ApiCredential = apiCredential

        'set eBay Site target to US
        apiContext.Site = SiteCodeType.US

        Return apiContext

    End If

End Function
4

1 回答 1

3

问题不是Transactions存在,Nothing而是apiCall存在Nothing

确保将apiCall其初始化为正确的值。

于 2012-02-01T12:42:24.660 回答