Skip to main content
Question

I'm receiving a BoxSessionInvalidatedException error.

  • May 22, 2025
  • 2 replies
  • 32 views

Forum|alt.badge.img

I'm using the Box.V2 v3.20.0 via NuGet with a .NET 4.5 project.

 

To get experience with the Box SDK, I wanted to build a console app using the Developer Token to eventually locate a particular document within folders available to me.  To start I wanted to just get the list of folders.  I've tried to replicate the samples I've found for this, but so far have not had success.

 

I'm using the Developer Token, Client ID, and Client Secret from the app configuration page in my Box account.

 

When I run the code, I get this error:

Exception of type 'Box.V2.Exceptions.BoxSessionInvalidatedException' was thrown.

 

I feel like there's something simple I'm overlooking, but I don't know what it is.

 

using System;
using System.Threading.Tasks;
using Box.V2.Auth;
using Box.V2.Config;

namespace Box.V2.Samples.TransactionalAuth
{
    class Program
    {
        private static string _clientId = "foo";
        private static string _clientSecret = "bar";
        static void Main(string[] args)
        {
            var developerToken = "baz";

            /* developer token
            var config = new BoxConfig("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET", new Uri("http://localhost"));
            var session = new OAuthSession("YOUR_DEVELOPER_TOKEN", "N/A", 3600, "bearer");
            var client = new BoxClient(config, session);
            */

            var config = new BoxConfig(_clientId, _clientSecret, new Uri("http://localhost"));
            var session = new OAuthSession(developerToken, "N/A", 3600, "bearer");
            var client = new BoxClient(config, session);

            Task t = MainAsync(client);
            try
            {
                t.Wait();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.InnerException.Message);
            }

            Console.Write("DONE >>>");
            Console.ReadLine();
        }

        private static async Task MainAsync(BoxClient client)
        {
            var items = await client.FoldersManager.GetFolderItemsAsync("0", 500);
        }
    }
}

 

2 replies

Forum|alt.badge.img

Hi, @WildcatMatt 

 

In this program, BoxSessionInvalidatedException occurred when DeveloperToken was wrong.
Is DeveloperToken correct?
Has the DeveloperToken expired?

 


Forum|alt.badge.img

I've been creating the Developer Token, using the copy button, then pasting it directly into my code, then executing the code within five minutes of when the token has been generated.