Skip to main content
Question

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

  • May 22, 2025
  • 2 replies
  • 30 views

Forum|alt.badge.img

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

Forum|alt.badge.img

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.


Forum|alt.badge.img

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