Following is the code which causing the issue.
public static byte[] ToByteArrayWithBom(this string s, Encoding encoding) {
var data = encoding.GetBytes(s);
long str = data.Length; // 323603364
var premble = encoding.GetPreamble();
var concatData = premble.Concat(data);
return concatData.ToArray();
// return encoding.GetPreamble().Concat(data).ToArray();
}
The function will work if there are less amount of data passed to this function.
When we are going to pass large amount of data then it is throw exception.
This is the place where we are facing problem concatData.ToArray();
. When we are converting var data into .ToArray()
then it is thrown exception.
I am not sure is there any max limit of .ToArray()
which will cause this issue or there is any other problem.
Exception Detail:
System.OutOfMemoryException
: Exception of typeSystem.OutOfMemoryException
was thrown
atSystem.Linq.Buffer…ctor(IEnumerable1 source)
atSystem.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)