0

I get error using this code:

var offer = Bot.NewTradeOffer(dbSteamId);

    offer.Items.AddMyItem(730, 2, 2611100148);

    if (offer.Items.NewVersion)
    {
        string newOfferId;
        if (offer.SendWithToken(out newOfferId, dbToken, dbMessage))
        {
            Log.Success("Trade offer sent : Offer ID " + newOfferId);
            Bot.TryGetTradeOffer(newOfferId, out offer);
        }
     }

It crashes with error:

ERROR: System.NullReferenceException: Object reference not set to an instance of an object. 
at SteamTrade.TradeOffer.TradeOfferManager.IsOfferValid(Offer offer) in C:\Users\Robertas\Desktop\SteamBot-master\SteamTrade\TradeOffer\TradeOfferManager.cs:line 130
at SteamTrade.TradeOffer.TradeOfferManager.GetOffer(String offerId, TradeOffer& tradeOffer) in C:\Users\Robertas\Desktop\SteamBot-master\SteamTrade\TradeOffer\TradeOfferManager.cs:line 162
at SteamBot.Bot.TryGetTradeOffer(String offerId, TradeOffer& tradeOffer) in C:\Users\Robertas\Desktop\SteamBot-master\SteamBot\Bot.cs:line 331
at SteamBot.TradeOfferUserHandler.SendTradeOffer() in C:\Users\Robertas\Desktop\SteamBot-master\SteamBot\TradeOfferUserHandler.cs:line 81
at SteamBot.TradeOfferUserHandler.OnLoginCompleted() in C:\Users\Robertas\Desktop\SteamBot-master\SteamBot\TradeOfferUserHandler.cs:line 64
at SteamBot.Bot.<HandleSteamMessage>b__5(LoginKeyCallback callback) in C:\Users\Robertas\Desktop\SteamBot-master\SteamBot\Bot.cs:line 476
at SteamKit2.CallbackMsgExtensions.Handle[T](ICallbackMsg msg, Action`1 handler)
at SteamBot.Bot.HandleSteamMessage(ICallbackMsg msg) in C:\Users\Robertas\Desktop\SteamBot-master\SteamBot\Bot.cs:line 458
at SteamBot.Bot.BackgroundWorkerOnDoWork(Object sender, DoWorkEventArgs doWorkEventArgs) in C:\Users\Robertas\Desktop\SteamBot-master\SteamBot\Bot.cs:line 941

Any ideas? Maybe you know different way to check trade offer state? Please share your ideas. Thanks!

EDITED:

public bool GetOffer(string offerId, out TradeOffer tradeOffer)
{
    tradeOffer = null;
    var resp = webApi.GetTradeOffer(offerId);
    if (resp != null)
    {
        if (IsOfferValid(resp.Offer))
        {
            tradeOffer = new TradeOffer(session, resp.Offer);
            return true;
        }
        else
        {
            //todo: log steam api is giving us invalid offers.
            Console.WriteLine("Offer returned from steam api is not valid : " + resp.Offer.TradeOfferId);
        }
    }
    return false;
}

resp.Offer is null. How can it be null? I could mention that everything works when bot send to my account, but when it sends to other account, it crashes.

EDITED #2:

Ok, I have found bug. It is problem by getting response. When i call this(http://api.steampowered.com/IEconService/GetTradeOffer/v1/?key=48B9FCE3FE8A74ADDA29174BFD47441B&tradeofferid=530787948&language=en_us):

{
"response": {

}

}

When I call this(http://api.steampowered.com/IEconService/GetTradeOffer/v1/?key=48B9FCE3FE8A74ADDA29174BFD47441B&tradeofferid=530796219&language=en_us):

{
"response": {
    "offer": {
        "tradeofferid": "530796219",
        "accountid_other": 213128749,
        "message": "Security Code: HqaMyUDN",
        "expiration_time": 1435675048,
        "trade_offer_state": 2,
        "items_to_receive": [
            {
                "appid": "730",
                "contextid": "2",
                "assetid": "2275856684",
                "classid": "310776767",
                "instanceid": "0",
                "amount": "1",
                "missing": false
            }
        ]
        ,
        "is_our_offer": false,
        "time_created": 1434465448,
        "time_updated": 1434465448,
        "from_real_time_trade": false
    },...

Any ideas why one response is empty, but other is normal?

Robis
  • 5
  • 1
  • 7
  • 4
    possible duplicate of [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Sayse Jun 16 '15 at 13:27
  • As Sayse mentioned, check your Nullreference Exception. Debug through your code, check where and why the exception occurs and fix it. If you need more specific help, you also need to be more specific. – Dolgsthrasir Jun 16 '15 at 13:29
  • You can use a decompiler to investigate a code of IsOfferValid – Viacheslav Smityukh Jun 16 '15 at 13:35
  • Take a look at EDITED – Robis Jun 16 '15 at 14:13
  • I don't know much about this specific technology, but resp.Offer can be null, I don't see why not. How is that webApi object created? Are you certain that offerId exist in the context the GetTradeOffer is searching for it? you said it works for one account and not for the other. Maybe it is searching if that account has that offer? In any case, it seems to me that it is possible for GetTradeOffer to return a null offer, ergo you need to deal with that, check what other information you have in resp, it may give you a clue. – Dzyann Jun 16 '15 at 14:28
  • Information in resp are different. Why? – Robis Jun 16 '15 at 14:45

1 Answers1

1

It appears you're using the SteamBot library. Since its source code is readily available, take a look at the source code for the GetTradeOffer method, found here: TradeOfferWebApi source

It's clear that receiving a non-null response from this method does NOT guarantee that it will contain a valid Offer object. Your check for resp.Offer, therefore, should first verify it's not null:

    if (resp != null)
    {
        if (resp.Offer != null && IsOfferValid(resp.Offer))

As to determining why it's not null: grab the source code to SteamBot, run your app + the SteamBot project within a debugger, and step into the method. Based on the source code for the GetTradeOffer method, it is most likely throwing an exception.

The library appears to be a work-in-progress anyway, given the quantity of 'todo' comments in the code, so running with the SteamBot source code might be helpful for debugging purposes (you can easily modify the source code to actually log the exceptions to a destination that will be useful to you).

EDIT (in response to OP's edit #2): From the docs to Steam's IEconService API, an account can only retrieve information on an offer to or from that account. The likely explanation is that either you're passing an invalid offer ID (which you've probably ruled out) or the account under which your app is running doesn't have rights to view this offer.

SWalters
  • 3,416
  • 5
  • 27
  • 37