❔ Invalid Data Exception when extracting files
I am getting a
System.IO.InvalidDataException: Found invalid data while decoding.
error while running this line...
Though I have no idea why. The file that I am extracting is one that has been downloaded, with the following code: https://pastecode.io/s/2rhskczr
Is there something i'm missing here?9 Replies
You are doing bad things with async code...
Your file is probably corrupted.
Are you not getting compiler warnings for doing things like this without an await?
Your use of .Result everywhere is bad. Don't use the async versions of those methods if you aren't going to actually write async code.
If this is supposed to be a zip file, does using another mechanism for extracting the file(s) work? For instance, using Expand-Archive from PowerShell
Got it. I thought there were only the async methods, and I can't have this be async as of now
I'll come back with results
not really!
Oh yeah, I didn't try that. It is corrupt.
Yeah you aren't waiting for the async write to finish before looping so it could be still in progress when you do another write on top of it.
Just make everything sync, or make your method async.
And use await appropriately.
Yeah it works now. I read up on some resources about Async and I figured out a solution for it. It doesn't work like I thought it did. Thank you!
Well, shameless plug, last week this discord hosted the Solution1 conference and I gave a talk on the topic of async code (among other things) that you might find helpful:
https://youtu.be/8lUs9ukVrFY
Oh that's amazing!!! Do you happen to know the timestamp for the asyncio talk?
That's the one where I have the most trouble on
Forgive me but, ping @mtreit
I'm currently doing aerosol so I can't really move, might aswell watch
The second half of the talk is basically about async
I see, thank you!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.