question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

  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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
mwwodacommented, Mar 2, 2022

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.

0reactions
WolfieBlincommented, Feb 7, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found