.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
-
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.
-
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
サインインしてコメントを残してください。
コメント
5件のコメント