Skip to main content
Box Employee
May 22, 2025 7:54 AM UTC
Question

Box.V2.JWTAuth.BoxJWTAuth.GetToken throws NullReferenceException (.NET)

Trying to upload a file to Box using the Box API for .NET using the following code:

 

Dim reader As StreamReader = New StreamReader("box.credentials.json")
Dim json As String = reader.ReadToEnd()
Dim config As IBoxConfig = BoxConfig.CreateFromJsonString(json)

Dim sdk As BoxJWTAuth = New BoxJWTAuth(config)
Dim token As String = sdk.AdminToken()
Dim client As BoxClient = sdk.AdminClient(token)

 

Unfortunately, the line "Dim token As String = sdk.AdminToken()" is throwing a NullReferenceException.

I am using Visual Studio 2015, target .NET framework is 4.6.  The API is served by Box.V2.dll version 1.0.0.0.

 

Can anyone help with this problem?

Thanks,

Ronny

    2 replies

    Box Employee
    May 22, 2025 7:54 AM UTC

    Hi ,

     

    Off hand I don't see anything anything directly wrong with the code, as this is what I'm using for my C# code:

     

    // Configure Box SDK instance
    var reader = new StreamReader("config.json");
    var json = reader.ReadToEnd();
    var config = BoxConfig.CreateFromJsonString(json);
    var sdk = new BoxJWTAuth(config);
    var token = sdk.AdminToken();
    BoxClient client = sdk.AdminClient(token);

     

    The one thing that I can say is it might be worth making sure that the content of your .json file is correct (should be directly downloaded from the Box app and not modified in any way) and that it's actually being read in correctly.

    Translate
    Box Employee
    May 22, 2025 7:54 AM UTC

    Thanks, I figured it out - the app needed to be submitted for authorization.

    Translate