Box CLI suddenly throws Object reference not set error
AnsweredMy Box CLI (running on Windows) was working just fine up until today when suddenly it stopped working and is now throwing a "Object reference not set to an instance of an object" error when I attempt to run any box commands in the command prompt. Even attempting a simple "box -h" command gives me the same error.
I have 1) rebooted, 2) re-installed, and 3) un-installed followed by a re-install and nothing seems to work. I did not delete or install anything new to my Windows server. I am using the Box CLI commands in a Windows service so it is continuously executing these commands BUT I set a 2 second delay between each command to avoid hitting rate limits (and creating a CPU-intensive cycle). That said, I am wondering if Box has somehow shut down CLI-based requests from my server.
Anyhow have any ideas?
-
OK so I was able to solve this issue with additional trial-and-error. To begin with, the issue seems to have been caused by a corruption of the Box CLI config files found in the user settings folder. These files get automatically generated by Box CLI the first time a user runs a Box command. I believe the issue was due to me being logged into multiple Windows sessions where in both session Box CLI was being accessed at the same time. This seemed to cause a corruption in the config files.
What I did to fix this issue was the following:
- Navigated to c:\Users\{username}\AppData\.box
- Note the .box is the folder where CLI generates and maintains the config files, token cache, etc
- In this folder were 3 files: box_environments.json, cache.json and settings.json
- I moved (i.e. not deleted) these files to a temp folder.
- I opened a command prompt and ran a simple box command. In this case I just typed in box -h. This triggered CLI to regenerate these files AND (most importantly) the error I was seeing was no longer there. (Yay!)
- Note that this does wipe out your environments and settings (e.g. downloads folder) so you can either manually recreate these in the Box CLI or try copying back in the config files you moved in the third step above. The problem is that if you copy in the same files you might end up bringing back the same error you started out with. What I did was first copy the box_environments.json and then retried a box command (e.g. box folders list-items 0). That worked for me. The next thing was that I copied back in was the settings.json file and retried. That's when I received the error (so that was basically the file that got pooched). I didn't bother copying back the cache as it simply stores the token and Box CLI will automatically get a new one anyways.
Two important lessons learned:
- Two separate Windows user sessions (with the same user logged in) concurrently running Box commands will both access the same .box setting files and will run the chance of corrupting these files. Careful--especially if you are running any Box commands through the same Windows service account in multiple services/processes/etc.
- Even when Box CLI is cleanly uninstalled it does not remove any of the user AppData, this will need to be manually fixed.
- Navigated to c:\Users\{username}\AppData\.box
Please sign in to leave a comment.
Comments
2 comments