Skip to content
This repository has been archived by the owner on Oct 28, 2019. It is now read-only.

NullReferenceException when accessing "steamLogin" cookie #197

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

opello
Copy link

@opello opello commented Dec 23, 2015

The latest Idle Master was never able to load the badge page for me, but it seemed like everything should be working according to a Wireshark capture. Then I looked in error.log:

12/22/2015 6:52:55 PM   CookieClient -> GetHttpAsync, for url = http://steamcommunity.com/profiles/76561197992873512/badges/?p=1
System.Net.WebException: An exception occurred during a WebClient request. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at System.Net.WebClient.DownloadBitsState.SetResponse(WebResponse response)
   at System.Net.WebClient.DownloadBitsResponseCallback(IAsyncResult result)
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at IdleMaster.CookieClient.<GetHttpAsync>d__5.MoveNext()

I did some additional debugging and came up with the fix I'm proposing here. It's too bad that the test isn't a single lookup, but I don't think there will be a large number of cookies to iterate through. If this proposed change is undesirable for that reason I think larger changes to get access to a System.Web.HttpCookieCollection would be required. I also thought about catching the NullReferenceException on the access of the CookieCollection but this seemed cleaner.

@NotTsunami
Copy link

+1, should definitely merge @jshackles

@goto1134
Copy link

goto1134 commented Jan 4, 2017

This works, thanks!

This was referenced Jan 4, 2017
@treloret
Copy link
Contributor

treloret commented Jan 4, 2017

By checking the cookie, not the value for a null you do have a single lookup.

@opello
Copy link
Author

opello commented Jan 5, 2017

@treloret I think what you've done in #243 is just fine. I didn't go check the Item[String] exception behavior when implementing my solution and I prefer to "look before you leap" or use "defensive programming" when handling user input which is what I consider cookies. But Item[String] will only raise an ArgumentNullException and the argument is a static string.

Thought this was a similar to a fix that was proposed december 2015, seems I fixed it with a less brute force approach.

I would argue that your implementation is not "less brute force" than mine because of how the Item[String] accessor is implemented.

When the steamLogin cookie was not in the collection a
NullReferenceException was caught and propagated out which prevented the
badge page from ever loading.
@opello
Copy link
Author

opello commented Jan 5, 2017

I updated this PR with a new fix. Instead of iterating the cookie collection directly one lookup is performed and cached locally. The cached instance is tested for null (the original problem) and then for the value "deleted" (the original goal). It worked for me locally.

@kaue
Copy link

kaue commented Jan 5, 2017

@opello can you compile?

@treloret
Copy link
Contributor

treloret commented Jan 5, 2017

Works nicely

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants