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

SOLVED
Go to solution
Highlighted
New Contributor

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

Tags (2)
2 REPLIES 2
Highlighted
Box Employee

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

Hi @ronnysh,

 

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.

Highlighted
New Contributor

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

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