title: xero c# "The current TokenRepository doesn't have a current request token"
body: <p>Have managed to connect to xero API and get an request token. however after restarting the project (for debugging), it mostly gives the following error when asking for an Access Token</p>
  
  <p><code>The current TokenRepository doesn't have a current request token</code></p>
  
  <p>as per my understanding and observation, the error is randomly raised. i.e sometimes it shows and sometimes it doesnt. the relevant code is as follows:</p>
  
  <pre><code>public class HomeController : Controller
      {
  
          IOAuthSession oauthSession = ServiceProvider.GetCurrentSession();
          //
          // GET: /Home/
  
  
          public ActionResult XeroConnect()
          {
              Session.Clear();
  
              Repository repository = ServiceProvider.GetCurrentRepository();
  
              oauthSession.MessageLogger = new DebugMessageLogger();
  
  
              // Can we already access an organisation??
              if (oauthSession.HasValidAccessToken &amp;&amp; repository != null &amp;&amp; repository.Organisation != null)
              {
                  return new RedirectResult("~/");
              }
  
              if (oauthSession is XeroApiPrivateSession)
              {
                  throw new ApplicationException("The current private session cannot access the authorised organisation. Has the access token been revoked?");
              }
  
  
              var callbackUri = new UriBuilder(Request.Url.Scheme, Request.Url.Host, Request.Url.Port, "Home/Callback");
              RequestToken requestToken = oauthSession.GetRequestToken(callbackUri.Uri);
  
          string authorisationUrl = oauthSession.GetUserAuthorizationUrl();
  
              return new RedirectResult(authorisationUrl);
          }
  
          public ActionResult Callback()
          {
              string verificationCode = Request.Params["oauth_verifier"];
              AccessToken accessToken = oauthSession.ExchangeRequestTokenForAccessToken(verificationCode); // error shows here
  
              GetAndStoreAuthorisedOrganisationName();
  
              Repository repository = ServiceProvider.GetCurrentRepository();
  
             List&lt;XeroApi.Model.Invoice&gt; invoices = (from invoice in repository.Invoices
                            where invoice.LineItems.Count &gt; 0
                            select invoice).ToList();
  
              return View(invoices);
          }
  }
  </code></pre>
  
  <p>any help appreciated. am also clearing the sessions before a new request token is asked for.</p>