Home > other >  How can I set C#'s gcAllowVeryLargeObjects to true in VS2022 **without** using an App.config fi
How can I set C#'s gcAllowVeryLargeObjects to true in VS2022 **without** using an App.config fi

Time:04-15

I want to be able to programmatically (or at least using the Project properties) set gcAllowVeryLargeObjects to true. I know I can use the App.config file, but this is quite ugly as it needs to create a separate file to the main executable which then needs to be passed around with the executable.

I've experimented with both Environment.GetEnvironmentVariable("gcAllowVeryLargeObjects") and Environment.GetEnvironmentVariable("COMPlus_gcAllowVeryLargeObjects"), but it doesn't print out anything, even if I set gcAllowVeryLargeObjects to true using a config file.

If that doesn't work, I don't expect Environment.SetEnvironmentVariable() to work either, and sure enough, it doesn't.

I've had a good look in the Project properties of VS2022, and there's nothing to be seen there either.

CodePudding user response:

It isn't possible.

But you can workaround it:

  1. Make the app.config an embedded resource or similar.
  2. At startup, check if the file exists.
  3. If it doesn't, read the resource and write the file.
  4. Let the app restart itself.
  • Related