.NET SDK code hangs at AdminToken()

Highlighted
First-time Contributor

.NET SDK code hangs at AdminToken()

I have adapted boilerplate code from the Box SDK documentation using the .NET SDK that is able to successfully connect and upload files using the Dev Token authentication.  However, when I attempt to authenticate using the JWT method, my code just hangs at the AdminToken() call.  It never throws an error or times out.  The code just sits waiting for a response that never arrives.  As shown below, I can reach a breakpoint at the first line, but a breakpoint at the second line is never reached.

 

     var adminToken = boxJWT.AdminToken(); 

     var client = boxJWT.AdminClient(adminToken);

 

I'm not sure how to troubleshoot this issue at this point and any guidance would be greatly appreciated.

 

Brian Furner  

 

 

5 REPLIES 5
Highlighted
New Contributor

Re: .NET SDK code hangs at AdminToken()

Was this problem ever resolved, or was it just ignored?

Highlighted
First-time Contributor

Re: .NET SDK code hangs at AdminToken()

I am having this issue right now also!

 

I would like to know how to resolve this issue, it is preventing me from completing my project

Highlighted
New Contributor

Re: .NET SDK code hangs at AdminToken()

This is may be related to a known Box issue (https://github.com/box/box-windows-sdk-v2/issues/638).   I was able to determine the AdminToken() method was hanging when invoked on the main thread of a WebAPI Controller.  I was able to successful bypass the issue by spawning a new thread to execute the logic that ultimately invokes the AdminToken() method.

Highlighted
Occasional Contributor

Re: .NET SDK code hangs at AdminToken()

@adblondin is correct.

You can get this to work if you create the AdminToken in a thread other than your controller thread. 

This is what worked for me:

 

 

BoxClient _boxClient = null;
var thread = new System.Threading.Thread(() =>
{
   var boxJWT = new BoxJWTAuth(boxConfig); // create boxConfig elsewhere
   var adminToken = boxJWT.AdminToken(); // create adminToken in new thread
   _boxClient = boxJWT.AdminClient(adminToken); // set your _boxClient
});
thread.Start(); // start the thread
thread.Join(); // wait for the thread to finish (ugly code).
Debug.Assert(_boxClient != null); // success!

 

 

This is discussed in depth here: 

https://github.com/box/box-windows-sdk-v2/issues/638

 

Highlighted
Box Employee

Re: .NET SDK code hangs at AdminToken()

Hey Everyone, 

 

We are aware of the issue with getting Admin Tokens using the .NET SDK. We have a PR that is working its way through the process. Once that PR lands successfully we will cut a new release of the SDK. Our ETA for this is early next week. 


Thanks,

John Townsend