box / box-windows-sdk-v2

Windows SDK for v2 of the Box API. The SDK is built upon .NET Framework 4.5

Home Page:https://developer.box.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UploadNewVersionUsingSessionAsync always throws InvalidCastException and creates multiple new versions

ChristianGalla opened this issue · comments

Description of the Issue

Every call of BoxClient.FilesManager.UploadNewVersionUsingSessionAsync throws System.InvalidCastException. Also, multiple new versions appear in Box after only one call of this method.

Steps to Reproduce

  1. Upload a new ~20 MB file using BoxClient.FilesManager.UploadUsingSessionAsync.
    Result: A new file is uploaded to Box.
  2. Upload a new ~20 MB version of the same file using BoxClient.FilesManager.UploadNewVersionUsingSessionAsync.
    Result: In Box there are now 6 new versions of the same file and a System.InvalidCastException is thrown.

Expected Behavior

Only one new version is uploaded without throwing an exception.

Error Message, Including Stack Trace

System.InvalidCastException: Unable to cast object of type 'Box.V2.Models.BoxEntity' to type 'Box.V2.Models.BoxFile'.
   at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonConverter[] converters)
   at Box.V2.Converter.BoxJsonConverter.Parse[T](String content)
   at Box.V2.Extensions.BoxResponseExtensions.ParseResults[T](IBoxResponse`1 response, IBoxConverter converter)
   at Box.V2.Managers.BoxResourceManager.<ToResponseAsync>d__11`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Box.V2.Managers.BoxFilesManager.<CommitFileVersionSessionAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Box.V2.Managers.BoxFilesManager.<>c__DisplayClass19_0.<<UploadSessionAsync>b__2>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Box.V2.Utility.Retry.<ExecuteAsync>d__3`1.MoveNext()
   --- End of inner exception stack trace ---
   at Box.V2.Utility.Retry.<ExecuteAsync>d__3`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Box.V2.Managers.BoxFilesManager.<UploadSessionAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Box.V2.Managers.BoxFilesManager.<UploadNewVersionUsingSessionAsync>d__17.MoveNext()

Screenshots

File in Box before call of UploadNewVersionUsingSessionAsync:
Before

File in Box after one call of UploadNewVersionUsingSessionAsync:
After

Versions Used

.Net SDK: 3.24.0
Newtonsoft.Json: 12.0.3
Windows: Server 2012 R2 / Windows 10 2004

I am facing this issue and would like to know if there is any estimate on timing for the fix or at least a workaround. I have a large migration coming up and will need to upload many large file versions.

@keithgagne In our case, the new version always was uploaded correctly, only multiple versions were created and the exception was thrown.
If it is ok for you to have multiple versions in Box, you can simply catch and ignore this error. I did the same but to be sure, I additionally compared the hash of the newest version in Box to the hash of the local file.

@ChristianGalla Thanks for the info! I ended up just using the UploadNewVersionAsync method even for large files and that seems to be working fine.

Box SDK Version 3.24.0 - 3.26.0 have the problem. Please install 3.23.0 to avoid the bug.

Uninstall-Package Box.V2
Install-Package Box.V2 -Version 3.23.0

Experiencing same issue. It would be good if a member of Box could comment on this issue, e.g. confirm issue and/or recommend the workarounds presented in previous comments.

Experiencing the same issue in all versions from 3.23 to 4.1. I am now forced to use version 3.22. I would really appreciate if some of the developers check it and fixed it since this bug is open from Nov 24, 2020.

Hi all. Sorry for such a late reply. The fix is already in the main branch and will be shipped with the next package release.