ExecuteWebRequest throws null exception when no network connection?

Aug 20, 2014 at 11:19 AM
Edited Aug 20, 2014 at 12:25 PM
I'm new to using this API, and to test error handling when trying to get credentials with no available network connection I pulled the (network) cable out of my computer and proceeded to (try to) debug the program.
Some values can be pulled out of the exception that's thrown by the API, but others give NullReferenceExceptions, including using exception.ToString().

Is there a bug in the exception handling in Tweetinvi.WebLogic.WebRequestExecutor.ExecuteWebRequest in the API or am I just being stupid here?

I'm using v0.9.3.4, which is supposedly the latest version available for download, however when I look at the source code repository for the latest release version, some of the files in the repository have notable changes compared to the source code files in the zip file I downloaded (which is clearly labeled]
ie. the downloaded copy does not have the function ExceptionHandler.GenerateTwitterException
ITemporaryCredentials applicationCredentials = null;
IOAuthCredentials newCredentials = null;
    applicationCredentials = CredentialsCreator.GenerateApplicationCredentials(consumerKey, consumerSecret);
    string url = CredentialsCreator.GetAuthorizationURL(applicationCredentials);
    var captcha = Console.ReadLine();
    newCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(captcha, applicationCredentials);
    TwitterCredentials.ApplicationCredentials = newCredentials;
catch(Exception e)
    if (e == null)
        Console.WriteLine("Exception e is null");
        Console.WriteLine("--- Start Stack Trace ---\n{0}\n--- End Stack Trace ---", e.StackTrace);
        if (e.InnerException == null)
            Console.WriteLine("InnerException of e is null");
        catch (NullReferenceException n)
            Console.WriteLine("--- Start Stack Trace 2 ---\n{0}\n--- End Stack Trace 2 ---", n.StackTrace);
The above code generates the following Console ouput (oauth key and directory info removed):
Header OAuth oauth_callback="oob",oauth_consumer_key="---",oauth_nonce="---",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1408528263",oauth_version="1.0",oauth_signature="---"
A first chance exception of type 'Tweetinvi.Logic.Exceptions.TwitterException' occurred in Tweetinvi.WebLogic.dll
--- Start Stack Trace ---
   at Tweetinvi.WebLogic.WebRequestExecutor.ExecuteWebRequest(HttpWebRequest httpWebRequest)
   at Tweetinvi.WebLogic.TwitterRequester.ExecuteQueryWithTemporaryCredentials(String url, HttpMethod httpMethod, ITemporaryCredentials temporaryCredentials, IEnumerable`1 parameters)
   at Tweetinvi.Credentials.WebTokenCreator.GetAuthorizationURL(ITemporaryCredentials temporaryCredentials, String callbackURL)
   at Tweetinvi.Credentials.WebTokenCreator.GetPinCodeAuthorizationURL(ITemporaryCredentials temporaryCredentials)
   at Tweetinvi.CredentialsCreator.GetAuthorizationURL(ITemporaryCredentials temporaryCredentials)
   at App_Namespace.MainWindow.TwitterAuth() in c:\some\folder\MainWindow.xaml.cs:line 122
--- End Stack Trace ---
Operation is not valid due to the current state of the object.
InnerException of e is null
A first chance exception of type 'System.NullReferenceException' occurred in Tweetinvi.Core.dll
--- Start Stack Trace 2 ---
   at Tweetinvi.Logic.Exceptions.TwitterException.ToString()
   at System.IO.TextWriter.WriteLine(Object value)
   at System.IO.TextWriter.SyncTextWriter.WriteLine(Object value)
   at System.Console.WriteLine(Object value)
   at App_Namespace.MainWindow.TwitterAuth() in c:\some\folder\MainWindow.xaml.cs:line 149
--- End Stack Trace 2 ---
I've also tried using this:
ExceptionHandler.WebExceptionReceived += (sender, args) =>
                  var exception = (ITwitterException) args.Value;
                  var statusCode = exception.StatusCode;
                  // etc etc
as suggested here by adaam2, and trying to pull all manner of data out through there but also to no avail.