UploadNewVersionUsingSessionAsync always throws InvalidCastException and creates multiple new versions
See original GitHub issue- I have checked that the SDK documentation doesn’t solve my issue.
- I have checked that the API documentation doesn’t solve my issue.
- I have searched the Box Developer Forums and my issue isn’t already reported (or if it has been reported, I have attached a link to it, for reference).
- I have searched Issues in this repo and my issue isn’t already reported.
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
- Upload a new ~20 MB file using BoxClient.FilesManager.UploadUsingSessionAsync. Result: A new file is uploaded to Box.
- 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:
File in Box after one call of UploadNewVersionUsingSessionAsync:
Versions Used
.Net SDK: 3.24.0 Newtonsoft.Json: 12.0.3 Windows: Server 2012 R2 / Windows 10 2004
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
InvalidCastException Class (System)
An InvalidCastException exception is thrown when the conversion of an instance of one type to another type is not supported. For example, attempting...
Read more >c# - InvalidCastException for Object of the same type
I have a very wired error, one of my custom controls seems that is create two compiled files, and when I try to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
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.