尝试发送蒸汽报价时,对象引用未设置为对象错误的实例

时间:2014-12-28 06:26:07

标签: c# steambot

我正在使用一个名为SteamBot的预构建c#程序。我收到的错误对于像我这样的初学者来说似乎很常见。但是我已经从堆栈溢出尝试了多个解决方案。我收到一个未设置为对象实例的" Object引用"错误。更具体地说,这里的错误..

Exception caught in BotCommand Thread: System.NullReferenceException: Object reference not set to an instance of an object.
   at SteamTrade.TradeOffer.OfferSession.Request(String url, NameValueCollection data, String referer, String tradeOfferId, String& newTradeOfferId) in c:\Users\Braden\Desktop\SteamBOT-ExchangeBOT\SteamTrade\TradeOffer\OfferSession.cs:line294
   at SteamTrade.TradeOffer.OfferSession.SendTradeOfferWithToken(String message,
 SteamID otherSteamId, TradeStatus status, String token, String& newTradeOfferId) in c:\Users\Braden\Desktop\SteamBOT-ExchangeBOT\SteamTrade\TradeOffer\OfferSession.cs:line 281
   at SteamTrade.TradeOffer.TradeOffer.SendWithToken(String& offerId, String token, String message) in c:\Users\Braden\Desktop\SteamBOT-ExchangeBOT\SteamTrade\TradeOffer\TradeOffer.cs:line 146
   at SteamBot.TradeOfferUserHandler.OnBotCommand(String command) in c:\Users\Braden\Desktop\SteamBOT-ExchangeBOT\SteamBot\TradeOfferUserHandler.cs:line 85
   at SteamBot.Bot.HandleBotCommand(String command) in c:\Users\Braden\Desktop\SteamBOT-ExchangeBOT\SteamBot\Bot.cs:line 286

这是我使用SteamBot / SteamKit2方法完成的代码,一切都可以实际发送交易报价。以下是获取错误的代码:

    public override void OnBotCommand(string command)
    {
        if (command == "RequestTradeOffer")
        {
            var Anyone = true;

            Console.WriteLine("Please enter in your steam profile link:");
            var RequestedTradeOffer = Console.ReadLine();

            Console.WriteLine("Please enter in the item's name that you are sending:");
            var ItemBeingSent = Console.ReadLine();

            SteamID OtherPersonSID = new SteamID(RequestedTradeOffer).ConvertToUInt64(); 

            if (Anyone)
            {
                //creating a new trade offer with token
                var offerWithToken = Bot.NewTradeOffer(OtherPersonSID);

                switch (ItemBeingSent)
                {
                    case "Isaac":
                        if(offerWithToken.Items.AddTheirItem(281226834, 730, 2)) // ItemID, AppID, ContextID
                        {  
                             Console.WriteLine("Item added.");
                        }

                        break;

                    default:
                        break;
                }

                string otherUsersToken = "oFSBJC4G";

                if (offerWithToken.Items.NewVersion)
                {
                    string newOfferId = "";

                    // "token" should be replaced with the actual token from the other user
                    if (offerWithToken.SendWithToken(out newOfferId, otherUsersToken))
                    {
                        Console.WriteLine("Trade offer sent : Offer ID " + newOfferId);
                        Log.Success("Trade offer sent : Offer ID " + newOfferId);
                    }
                }
            }
        }
    }


Thanks in advance!

根据要求:提供专线281的功能

internal bool Request(string url, NameValueCollection data, string referer, string tradeOfferId, out string newTradeOfferId)
        {
            newTradeOfferId = "";

            string resp = Fetch(url, "POST", data, false, referer);
            if (!String.IsNullOrEmpty(resp))
            {
                try
                {
                    var offerResponse = JsonConvert.DeserializeObject<NewTradeOfferResponse>(resp);
                    if (!String.IsNullOrEmpty(offerResponse.TradeOfferId))
                    {
                        newTradeOfferId = offerResponse.TradeOfferId;
                        return true;
                    }
                    else
                    {
                        //todo: log possible error
                        Debug.WriteLine(offerResponse.TradeError);
                    }
                }
                catch (JsonException jsex)
                {
                    Debug.WriteLine(jsex);
                }
            }
            return false;
        }

进一步研究调试器,我发现了这个异常错误消息......

A first chance exception of type 'System.Net.WebException' occurred in System.dll
System.Net.WebException: The remote server returned an error: (400) Bad Request.
   at System.Net.HttpWebRequest.GetResponse()
   at SteamTrade.SteamWeb.Request(String url, String method, NameValueCollection data, CookieContainer cookies, Boolean ajax, String referer) in c:\Users\Braden\Desktop\SteamBOT-ExchangeBOT\SteamTrade\SteamWeb.cs:line 67
   at SteamTrade.TradeOffer.OfferSession.Fetch(String url, String method, NameValueCollection data, Boolean ajax, String referer) in c:\Users\Braden\Desktop\SteamBOT-ExchangeBOT\SteamTrade\TradeOffer\OfferSession.cs:line 47
A first chance exception of type 'System.NullReferenceException' occurred in SteamTrade.dll

0 个答案:

没有答案