Q:

C# Large JSON to string causes out of memory exception

I'm trying to download very large JSON file. However, I keep getting an error message:
"An unhandled exception of type 'System.OutOfMemoryException' occurred in mscorlib.dll"
{The function evaluation was disabled because of an out of memory exception.}
Any tips how I can download this large JSON filet? I have tried to use string and StringBuilder but no luck.
Here is my code:
public static string DownloadJSON(string url)
{
 try
 {
   String json = new WebClient().DownloadString(url); // This part fails!
   return json;
 }
 catch (Exception)
 {
  throw;
 }
}

I have created console application. I have tried this code with smaller JSON file and it worked. 
My idea is later to split this larger JSON file and put it to database. However I need to encode it before I can put it to database. I have not write yet database part or anything else, because downloading this big JSON causes problems. I don't need it as a stream, but that was my example way how I made encoding. I need to encode it because data have special characters like å.
I tried also this but same problem:
var http = (HttpWebRequest)WebRequest.Create(url);
            var response = http.GetResponse();

            var stream = response.GetResponseStream();
            var sr = new StreamReader(stream);
            var content = sr.ReadToEnd();

A:

I assume that you have very very large response. It is better to process stream. Now comes to point that cause outofmemoryexcetion.

In .net max size of any object 2GB. This is even for 64 bit machine. If your machine is 32 bit then this limit is very low.

In your case above rules get break so it will not work but if you have file size less than that then try to build your code against 64 bit and it will give your result.

