Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.OutOfMemoryException when packaging/publishing Azure project

I've been trying to package/publish my Azure project for awhile now (but to no avail). I've tried the following:

  • Right-click -> package/publish from Visual Studio (OutOfMemoryException)
  • CSPack (I closed it after it still kept running even after close to 2 hours)
  • MSBuild (OutOfMemoryException)

How do I circumvent this OutOfMemoryException? I'm currently running VS2012 with 12GB of RAM, so while I think the project is quite large (many, many subprojects), I'd think my machine would be able to handle it. The exception is as follows:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\Windows Azure Tools\2.1\Microsoft.WindowsAzure.targets(2866, 5): error : Exception of type 'System.OutOfMemoryException' was thrown. [C:\Users\..\WindowsAzure.ccproj]

It's been very frustrating, I'd be extremely grateful if anyone could offer me some friendly advice!

like image 799
matt Avatar asked Jun 05 '14 18:06

matt


People also ask

What causes system OutOfMemoryException?

An OutOfMemoryException exception has two major causes: You are attempting to expand a StringBuilder object beyond the length defined by its StringBuilder. MaxCapacity property. The common language runtime cannot allocate enough contiguous memory to successfully perform an operation.

How do you fix system OutOfMemoryException exception of type system OutOfMemoryException was thrown?

OutOfMemoryException Exception of type 'System. OutOfMemoryException' was thrown. To resolve this issue, I had to restart Visual Studio or go to the Windows Task Manager and terminate IIS Express process. This error could happen due to a variety of reasons related to memory consumption of the application.

How can Outofmemory exception be prevented?

To avoid this exception while working with StringBuilder, we can call the constructor StringBuilder. StringBuilder(Int32, Int32) and can set the MaxCapacity property to a value that will be large enough to serve the accommodation required when we expand the corresponding StringBuilder object.


2 Answers

This error can occur not just because of the package size. We occasionally receive this error, but a simple restart of Visual Studio resolves the issue.

like image 82
Co7e Avatar answered Sep 29 '22 15:09

Co7e


This is typically caused by trying to place too much content into your package, not by how many projects you reference. There is a maximum size that can be placed into the .cspkg zip stream, and there is a maximum size of .cspkg that can be uploaded to Azure (600 MB).

You should remove all static content such as images, audio, or video from your package and instead place those assets into blob storage. You can change hrefs so that customers directly download the contents from blob storage, or you can use something like the Azure Boostrapper to download content to the VM on startup.

Also, btw, the amount of RAM you have on your machine is in no way related to getting OutOfMemoryException in any application (unless you have too small of a swap file, but that is a different issue).

like image 43
kwill Avatar answered Sep 29 '22 16:09

kwill