All Questions
Tagged with memorystream stream
116 questions
1
vote
1
answer
71
views
Write and read string from MemoryStream
Please consider this scenario:
I want to read a file and then place its bytes to MemoryStream and then write some strings to it and then immediately read entire MemotyStream. For example I have a text ...
0
votes
0
answers
51
views
.Net 6 StreamReader.ReadBlockAsync throw System.ObjectDisposedException when reading file
I have a problem when trying to read a file from an FTP server. Thousands of files have been read without problem. This problem only occurs for 1 file. The problem occurs when I use the method ...
1
vote
0
answers
321
views
How do i serialize a excel file stream?
I need to convert the Excel file into a stream with XLWorkbook (using ClosedXML.Excel) and then serialize with JSON format (Newtonsoft.Json) but a code error appears.
I already have a excel file saved ...
0
votes
0
answers
680
views
Getting the error: ReadTimeout = 'stream.ReadTimeout' threw an exception of type 'System.InvalidOperationException' when using MemoryStream instance
The specific message is "Timeouts are not supported on this stream'. I'm also getting a similar exception but for WriteTimeout.
This is my code. I am trying to write audio data to a MemoryStream ...
4
votes
1
answer
13k
views
HTTP POST multipart/formdata using HttpClient
When I post the below code using httpclient
using var formContent = new MultipartFormDataContent("NKdKd9Yk");
using var stream = new MemoryStream();
file.CopyTo(stream);
var fileBytes = ...
0
votes
0
answers
43
views
C# Can I configure 2 streams so that the contents of one continues to be passed to the other?
I have read this question/answer: How do I copy the contents of one stream to another?.
And I've read the doc pages of Stream.CopyToAsync and Stream.CopyTo.
I haven't found anything in any of them ...
1
vote
2
answers
918
views
Zip file downloaded from memory stream is empty/invalid
I'm trying to create a tool that takes images on my server, and downloads them to the user in a zip file. These images are Sitecore media items, that I'm getting the Stream from, and trying to copy ...
-2
votes
1
answer
576
views
How to override stream closing when returning stream C#
I would like to be able to return MemoryStream from my function but I think that when returning the stream its also automatically closed.
using (var httpStream = await httpClient.GetStreamAsync(link)) ...
-1
votes
1
answer
562
views
MemoryStream is not writing everything expected to the file
My problem is to write some data about passangers to the MemoryStream and then copy it to the file. I need to realize it in two different methods. In methods I need to use Stream, then in Main ...
2
votes
1
answer
747
views
MemoryStream is not writing anything to the file [duplicate]
My problem is to write some data about passangers to the MemoryStream and then copy it to the file. I need to realize it in two different methods. In methods I need to use Stream, then in Main ...
0
votes
1
answer
153
views
ASP.NET File function doesn't works with MemoryStream but if copied to temp file, it does
The following code works:
MemoryStream s = TarCreator.CreateTar(toDownload);
string path = Path.GetTempFileName();
using (var newFile = System.IO.File.OpenWrite(path))
s.CopyTo(newFile);
return ...
0
votes
1
answer
2k
views
Stream.Read() is Slow Performance
Converting Stream to Array by using memorystream.Read(arr, 0, length) for 19 Mb file.
When Running it in machine1 it takes approx 1.26 Sec, in Machine2 it takes approx 3 sec.
Why there is a difference ...
2
votes
1
answer
234
views
Uploading file using MemoryStream via WCF MessageContract to SQL FileStream is empty when it reaches service
I have googled my *** off and cannot find a reason why this is happening.
I have a WCF service (file) where I upload a PDF that is only in a memorystream. The memorystream shows I have data before it ...
0
votes
1
answer
2k
views
Is it possible to use Memory Stream how input file for FFMpeg?
I'm trying to work with ffmpeg in a .NET application. Is it possible to use a memory stream instead -i [string inputFilePath] to get some frames for example? Many thanks for any answer.
0
votes
2
answers
1k
views
Using statement around XmlWriter causes premature closing of stream [duplicate]
I'm trying to write a small piece of XML to a memory stream, then read the written content from the memory stream and save it to a variable.
I have the following logic that works for writing and ...
1
vote
1
answer
1k
views
C# - Cannot access a closed stream
My code for PDF creation with iTextSharp version 5.5.13.2 is returning error, "Cannot access a closed stream."
I am unsure how this error could arise as I have my code encapsulated within ...
1
vote
1
answer
359
views
Unable to create System.Drawing.Image object from WebResponse Stream
I am trying to create a System.Drawing.Image object from a WebResponse's response stream. Here's what I'm doing:
using (WebResponse response = await request.GetResponseAsync())
{
using (Stream ...
2
votes
1
answer
9k
views
Should I use Stream.CopyToAsync() to copy data from a network stream?
I am getting data from the NetworkStream of a TcpClient and I want to write the data into a fixed-length MemoryStream, because I know the size of the data.
I use Stream.CopyToAsync to write the data ...
0
votes
0
answers
17
views
MemoryStream upload to Minio results in size 0 [duplicate]
I am trying to copy data selectively from one Minio server to another with a c# windows application.
Data is downloaded OK, no exceptions occur, but file size in destination server is zero.
A little ...
0
votes
0
answers
706
views
Can MemoryStream reduce its capacity?
When I call MemoryStream.SetLength() and set length less than the current length, is it possible that MemoryStream would reallocate its buffer to reduce the capacity?
In other words, I know that when ...
4
votes
0
answers
233
views
How to poll through a memory stream while accessing that memory stream?
I am trying to build an app that streams music to another app. The receiver side reads bytes, then saves them into a temp file, and plays that temp file. But between parts of the song, there is a ...
0
votes
0
answers
162
views
Confusion over using Stream vs byte[] for transferring file content
What I want to achieve is to read a JPEG image from disk, resize it (reduce the resolution) and return the resulting image to a different module which is going to save the image to an AWS S3 bucket... ...
-2
votes
1
answer
5k
views
MemoryStream, how many bytes in kb?
I'm using .net core to upload an image file. The file is converted to a MemoryStream and then sent to a service which will validate the file. Currently I do that with something like this:
...
0
votes
2
answers
342
views
How can i read the data using the GZipStream.Read method
I can't read the data using the GZipStream.Read method. But I can read directly from MemoryStream. What am I doing wrong?
public static void Main(string[] args)
{
var memStr = new ...
3
votes
1
answer
676
views
C# nested stream with using statement, should I use two using?
I'm writing a piece of code which uses nested stream:
using (var zip = new ZlibStream(new MemoryStream(to_be_unziped), CompressionMode.Decompress))
{
}
Is it fine? Or should I write it as:
using (...
0
votes
1
answer
486
views
Can't Create MemoryStream using Custom File as Resource using C#
I am using C# and can't create a stream using a Resource. The file is a custom file called 'test.usr' which contains a string. The build action for it is set to None (not sure if that matters). The ...
0
votes
1
answer
3k
views
C# efficient reading of stream content with a limit on amount read
I have a case where a web API call returns a very large response of string. I make the call as follows:
var multipartContent = new MultipartFormDataContent();
multipartContent.Add(new ...
1
vote
1
answer
234
views
How to correctly create a thumbnail using C#?
I have a console application written using C# on the top of Core .NET 2.2 framework.
I want to create asynchronous Task that would write a full-size image to storage. Additionally, the process will ...
-1
votes
1
answer
2k
views
How can I append to a memoryStream in a foreach loop without overwriting it's contents?
I'm currently making api calls that return MemoryStream objects. I'm having issues iterating through a for loop and appending a memory stream to another using the copyTo method. It overwrites what was ...
-1
votes
2
answers
15k
views
c# how to save IO.Stream to MemoryStream and save to PDF file on local folder
I am calling a third party service, which return a pdf file by IO.Stream. I need to change to MemoryStream, and save to a pdf file.
1
vote
1
answer
400
views
memory efficient way to read from COM stream to c# byte[]
My current approach is to read the COM stream into a C# MemoryStream and then call .toArray. However, I believe toArray creates a redundant copy of the data. Is there a better way that has reduced ...
1
vote
1
answer
911
views
Stream is not filled when using a MemoryStream for PdfWriter output from iTextSharp
I have the following issue.
This code works fine
private void ModifyAndSavePDF(Stream sourceFile, string text)
{
using (var pdfWriterStream = new FileStream(@"d:/temp/test.pdf", FileMode.Create))...
0
votes
0
answers
441
views
MemoryStream Capacity Problem. Is there another stream class like memorystream, not memorytributary?
I'm trying to serialize a big data. I'm getting an error OutOfMemoryException when serialize data. I did some researches. I found some information that it is said that there is an error about ...
0
votes
0
answers
126
views
Copy generic stream without changing the positon
I hava a Stream which constantly gets accessed from another thread.
But I want to access it for a brief moment for doing some gpu heavy paint work in a UserControl.
I currently use Stream.CopyTo ...
1
vote
1
answer
2k
views
Error: Unexpected end of stream. Data might be corrupted
I'm trying something with stream data. I'm getting an error. I have some codes like below. One of both works, but another is not.
This code works properly.
private static void Main_2()
{
...
2
votes
1
answer
505
views
How to combine partially pre-cached MemoryStream with FileStream?
For a time-critical media presentation application, it is important that media files be presented right at the instance when the user selects it. Those files reside in a truly humongous directory ...
0
votes
1
answer
2k
views
Cannot access a closed stream when passing stream to another function
I need to pass a stream to a couple of functions in another class, but its throwing an error
Cannot access a closed stream
Here's the code:
first method:
Here it opens a file with File.Open ...
0
votes
1
answer
346
views
TallComponents.PDF.Document Error: "the document is corrupt, rebuilding failed"
I'm getting exception "the document is corrupt, rebuilding failed",
while instantiating TallComponents.PDF.Document from MemoryStream.
The byteResponse is good. that is, the document is NOT Corrupted....
1
vote
1
answer
2k
views
MemoryStream throws ObjectDisposedException when trying to access it in its own using statement
I'm trying to use streams to progressively display a jpeg as it loads. This used to work fine, but this morning I tried running my code and now no images can be loaded because of this error. The ...
-1
votes
1
answer
201
views
download file: ReadTimeout VB net
I want to download file from the path with VB net moves using MemoryStream but I have this exception:
ReadTimeout = 'Stream.ReadTimeout' a levé une exception de type 'System.InvalidOperationException'...
3
votes
0
answers
2k
views
How to use MemoryStream for more than 2GB of data on a 32 bit application?
sI have the following use case. I have a web service for downloading csv files.
Csv files are formed on the go, i.e., some data is retrieved from the database row by row and converted in the runtime ...
0
votes
1
answer
297
views
How to zip PDF and XML files which are in memorystreams
I'm working with VS2015 and ASP.Net on a webservice application which is installed in the AWS cloud.
In one of my methods i got two files, a PDF and a XML.
These files just exist as instances of ...
1
vote
1
answer
2k
views
Return stream immediately and then write to stream asynchronously
In my current code I have a method like this to read data from a device (pseudo code):
public async Task<string> ReadAllDataFromDevice()
{
var buffer = "";
using (var device = new ...
0
votes
0
answers
43
views
ASP.NET: Unable to cast IO.StreamWriter to IO.MemoryStream
I have a complex class module that make a lot of processing and return a object of type IO.StreamWriter, but I need cast this object to IO.MemoryStream, furthemore to Byte(). Finally it converts Byte()...
0
votes
0
answers
126
views
Dispose a memory stream from a argument out
I have code for which MemoryStream does not disposes the value.
MemoryStream ms = new MemoryStream();
string result = RandomFunction(out ms, string input) //the stream value is generated inside the ...
0
votes
0
answers
113
views
UnmanagedMemoryStream: read and write between managed and native code
I have been using MemoryStream and recently found out about `UnmanagedMemoryStream which is reported to be more efficient especially when dealing with large buffers. My question is:
Can one write to ...
1
vote
1
answer
2k
views
Modify stream in c#
I have a simple http server where people upload files and I just compress them and save them to disk. This is what I am doing I think people will understand better with code
/// <summary>
/// ...
0
votes
1
answer
281
views
Dispose and return value
I'm confused with streams, return value and dispose. I.e. I use Stream and want to return stream from method. Next code:
public async Task<HttpResponseMessage> GetOverlayAsync(string ...
0
votes
1
answer
426
views
Splitting audio signal to frames from memory stream resp. byte array [C#]
I am trying to implement VAD (Voice Activity Detection) algorithm in c# because I did not find any suitable library for this purpose.
Im not working with wave files but only with memory streams just ...
1
vote
1
answer
1k
views
Cannot write to new MemoryStream - Stream closed
I have methods that compress one or more files to either a tar(.gz) or a zip.
In these files I use bytes that I have already loaded in to memory, and I just need them to be compressed, and the ...