This article is a mirror article of machine translation, please click here to jump to the original article.

View: 24894|Reply: 0

[Source] Stream Stream use multiple precautions

[Copy link]
Posted on 8/2/2019 1:52:30 PM | | | |
System.ArgumentOutOfRangeException: 索引超出范围。必须为非负值并小于集合大小。
The exception thrown by the system log is shown in the following figure:



The reason for the exception is that when I save the stream, the system reads the stream beyond the size of the stream.

Use the same stream twice to note 2 points:

1. Stream will save a position: Stream.Position, which represents the position in the current stream, and each read will start from this position, and this position will be set to the last read position after the reading is completedThe first time I read the entire stream, the position reaches the end, and the second time I can't read the content.So you need to set the context before the second read. Request.InputStream.Position=0;

2. The using statement cannot be used for the first read. The using statement actually adds a try, finally block, in which the object's Dispose method will be executed. This way, the second read will not contain any content.


Resolution code:

Before saving the flow, call the following code:







Previous:Baidu Wangpan bypasses VIP restrictions and improves download speed
Next:Introduction and practice of NoSQL databases (based on MongoDB and Redis)
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com