Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9111267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:27:49+00:00 2026-06-17T03:27:49+00:00

This a moot question, as the amount I was allocating was wrong. It was

  • 0

This a moot question, as the amount I was allocating was wrong. It was supposed to be 400MB not 400GB… Sorry! The answers are good though.

I am trying to unit test a method of mine which throws an OutOfMemoryException if a large file is uploaded.

My problem is my unit test is also throwing this exception (for the same reasons I guess).

According to Task Manager, if I am reading the information correctly, I do have enough RAM so am not really sure why my unit test is failing in this way.

RAM usage

Here is the respective unit test code:

var data = new List<byte>();
for(UInt64 i = 0; i < 400ul * 1024ul * 1024ul * 1024ul; i += 65536ul)
{
    data.AddRange(new byte[65536]); // <-- throws exception here when i = 536870912
}
this.UploadedFileData = data.ToArray();

I tried the following before the above code:

var data = new byte[400ul * 1024ul * 1024ul * 1024ul];

This though, results in the error: Arithmetic operation resulted in an overflow.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:27:51+00:00Added an answer on June 17, 2026 at 3:27 am

    Are you on a 32 bit machine?

    The process limit is 2GB on 32-bit, unless you use the /3GB boot switch.

    From C# Increase Heap Size – Is It Possible

    It is possible that you need to do the below

    For very large List objects, you can increase the maximum capacity to 2 billion elements on a 64-bit system by setting the enabled attribute of the gcAllowVeryLargeObjects configuration element to true in the run-time environment.

    From http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx

    As David mentions, the code will require a lot of reallocations when it grows. To prevent performance costs and memory fragmentation, you should at the very least set Capacity to an appropriate amount, if not rewrite the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a moot question as I'm not on this project any more, but
This is not as much a programming question, as it is a configuration thing.
I recognise this is a moot point on the web database, so this question
This question is moot - see @Alochi comments. my bad. This is different than
this is my first question in here, and I would like to ask if
This question is directly related to this SO question I posed about 15 minutes
This question is kind of a follow up to this question I asked a
The better way to ask this question would be an example as follows What
This is driving me crazy. I'm not including any code because I want to
Though the question is very specific, I'd also really appreciate general advice and other

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.