locked
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown. RRS feed

  • Question

  • I get the following error anytime i change something in the XAML and try and build the project. If I change anything in the code behind it works everytime.... To get it to work i have to get out of the ide come back in place a space in one of the .vb files to change it then it will build..... Any ideas?

     

    Error 107 The "ResourcesGenerator" task failed unexpectedly.
    System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
       at System.IO.MemoryStream.set_Capacity(Int32 value)
       at System.IO.MemoryStream.EnsureCapacity(Int32 value)
       at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.IO.BinaryWriter.Write(Byte[] buffer, Int32 index, Int32 count)
       at System.Resources.ResourceWriter.WriteValue(ResourceTypeCode typeCode, Object value, BinaryWriter writer, IFormatter objFormatter)
       at System.Resources.ResourceWriter.Generate()
       at System.Resources.ResourceWriter.Dispose(Boolean disposing)
       at Microsoft.Build.Tasks.Windows.ResourcesGenerator.Execute()
       at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult) 

    Sunday, February 17, 2008 8:49 PM

Answers

  • Your description is too simple. I think that you can try to narrow down the scope of your problem. You can try to create a new project to see is it work well. You can also create a new project and copy your working project contents to the new project, you can check to see is it works well. You can use another computer to see is your project works well. After the investigations, you can determine that is this your project problem or even Visual Studio problem, so you can take action on the problem.

     

    Best Regards,

    Wei Zhou

    Tuesday, February 19, 2008 2:06 AM

All replies

  • Your description is too simple. I think that you can try to narrow down the scope of your problem. You can try to create a new project to see is it work well. You can also create a new project and copy your working project contents to the new project, you can check to see is it works well. You can use another computer to see is your project works well. After the investigations, you can determine that is this your project problem or even Visual Studio problem, so you can take action on the problem.

     

    Best Regards,

    Wei Zhou

    Tuesday, February 19, 2008 2:06 AM
  • Good day Wei.

    I am having the exact same problem.

    The root of the problem is resources. We include 166 image files of total size 244MB into the project (I know it is crazy, but we have to).

    If in Visual studio you set the "Build Action" to "Content" and "Copy to Output Directory" to "Copy if Newer" it works.

    This made me think that all the files are compiled into the resource file as one step and when there are too many it breaks. To test this I changed the "Build Action" back to "Resource" on some of the files. When 214MB worth of images were set to "Resource" the exception happened again.

    Hope this helps you track down the problem Smile

    Here is the exception I get:

    Error 3 The "ResourcesGenerator" task failed unexpectedly.
    System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
    at System.IO.MemoryStream.set_Capacity(Int32 value)
    at System.IO.MemoryStream.EnsureCapacity(Int32 value)
    at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
    at System.IO.BinaryWriter.Write(Byte[] buffer, Int32 index, Int32 count)
    at System.Resources.ResourceWriter.WriteValue(ResourceTypeCode typeCode, Object value, BinaryWriter writer, IFormatter objFormatter)
    at System.Resources.ResourceWriter.Generate()
    at System.Resources.ResourceWriter.Dispose(Boolean disposing)
    at Microsoft.Build.Tasks.Windows.ResourcesGenerator.Execute()
    at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult) Sygnia_FoHF_Pitch


    Thank you.
    Du Toit.
    • Proposed as answer by bogna Tuesday, September 13, 2011 8:19 AM
    Thursday, March 20, 2008 8:57 AM
  •  

    Thanks for the suggestion. I constantly get these errors and have to close visual studio. Such a pain. I tried your suggestion and it did not work for me.... must be some other issue. Maybe a resource dictionary. Not sure.... I actually just changed something and now i get

     

    Error 103 Unable to embed resource file  Not enough storage is available to complete this operation. 

     

    It wont rebuild at all... Such a POS....

     

    Thanks

    Aaron


     

    Monday, March 24, 2008 2:51 PM
  • Hi,

     

    I have the same issue when compiling my project "N" times.

     

    Seems like the .NET IDE is not releasing resources. I see that the TaskManager shows an increasing amount of memory usage for DEVENV.EXE until it blows up.

     

    Right now, my only solution to this problem is close the .NET IDE and re-open it again.

     

    Cleaning the solutoin doesnt help.

     

    Any ideas????

     

     

    thanks,

    Francis

     

    Wednesday, April 23, 2008 6:16 PM
  • Hi all,

    I've been having the same issue for a while also.  I already created a smaller solution (only 9 projects instead of 71), none of the project have any image.  My system has 2 gb of free ram when I build.  I get the out of memory error around 1 build every 3. 

    The stack displayed is :
    Error 107 The "ResourcesGenerator" task failed unexpectedly.
    System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
       at System.IO.MemoryStream.set_Capacity(Int32 value)
       at System.IO.MemoryStream.EnsureCapacity(Int32 value)
       at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)
       at System.IO.BinaryWriter.Write(Byte[] buffer, Int32 index, Int32 count)
       at System.Resources.ResourceWriter.WriteValue(ResourceTypeCode typeCode, Object value, BinaryWriter writer, IFormatter objFormatter)
       at System.Resources.ResourceWriter.Generate()
       at System.Resources.ResourceWriter.Dispose(Boolean disposing)
       at Microsoft.Build.Tasks.Windows.ResourcesGenerator.Execute()
       at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult) 

    This is very annoying, and I found nothing to solve it.
    Wednesday, April 30, 2008 3:51 PM
  • I also am getting a similar issue, although less often that others that have posted. It seems like when I am working in VS2008 for most of the day and have XAML resource dictionaries open for long periods of time it causes the issue. I am also running ReSharper and it runs into the same problem. The resource dictionary that causes the majority of the problems is a massive one (2400 lines).

    As for VS2008 itself, this usually happens after it leaks to using about 570MB of my system memory and my overall system memory usage hits around 75%.

    Things work fine again if I close out of VS and re-open it.
    Wednesday, April 30, 2008 9:02 PM
  • This is a huge problem for me to. Anybody found out why big WPF projects seem to grow in size. We also use XAML Resource dictionaries.
    Tuesday, October 14, 2008 4:44 PM
  • Remove Resharper. It doesn't  help me with xaml's, but helps when I'm editing sc files.
    Wednesday, October 15, 2008 4:47 AM
  • Hi All

    A customer has recently reported that he has been able to relieve some Visual Studio 2008 out of memory conditions by increasing the number of GDI handles from the default of 10,000 (Vista,Windows XP) to 20,000. If you wish to try this workaround, the relevant registry key is documented here

    http://msdn.microsoft.com/en-us/library/ms724291(VS.85).aspx

    since we have so far been unable to reproduce the condition in our labs, we can't guarantee that this will work for you, however we are looking into these reports and some corresponding Watson crash information, so we would very much appreciate your feedback on whether this workaround helps in your particular cases.

    In addition we would like to hear from anyone who is seeing this issue, whether you are using a pane layout in Visual Studio that lets the splitter bar (the separator between the XAML and designer views in the designer) change size during (say) a compile. Before applying the GDI workaround, if you can try doing Window->Reset Window Layout and then doing some work in the standard window layout, does the issue reproduce for you still?

    Thanks for your help and please accept my apologies for the inconvenience this issue is casuing you all.

    I'd also like to let you know that there's a specific forum for WPF & Silverlight Designer issues, at http://social.msdn.microsoft.com/Forums/en-US/vswpfdesigner/threads - this is a great place to raise issues with the WPF designer.

    Regards

    Mark Wilson-Thomas
    PM, WPF & Silverlight Designer Team, Visual Studio
    Mark Wilson-Thomas - Program Team - WPF & SL Designer for Visual Studio - posts are provided 'as-is'
    • Proposed as answer by snipe2009 Monday, October 5, 2009 7:23 PM
    Wednesday, August 19, 2009 4:26 PM
  •  
    My mistake has left the office only when System.Outofmemory a video with the MediaElement, as soon as I get this error lift, I think we have made good progress with this issue, please help me puden
    • Proposed as answer by snipe2009 Monday, October 5, 2009 7:27 PM
    Monday, October 5, 2009 7:26 PM
  • Thanks

    As suggested by Mark using the following link http://msdn.microsoft.com/en-us/library/ms724291(VS.85).aspx  and editing the registry value to 25000 soved my problem

    Registry Key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\GDIProcessHandleQuota
    • Proposed as answer by PavanPUne Tuesday, November 24, 2009 6:20 AM
    Tuesday, November 24, 2009 6:20 AM
  • Good evening,

    change registry didn't work for me.

    The problem was that the file "resources.resx" was not be "readable" by "visual studio" : "System.OutOfMemoryException" occured :(

    and i was not able to access Resource Menu in VS.

    My solution was to rename the file "resources.resx" and start VS. Program asked me to create another resource file.

    I simply changed the method to add all my embedded picture resources into the program. Before, i was using menu

    Resources\Images\Add Resource and select in Persistence menu : "Embedded in .resx". I used this code line to display image :

     

    PictureBox1.Image = CType
    (My
    .Resources.ResourceManager.GetObject(T(i, 1)), Image)
    

     

    Now, i add picture resource directly by right-clicking on "Resources" and select "Add Existing Item...". I used this code line to display image :

     

    PictureBox1.Image = New
     Bitmap(Me
    .GetType
    (), (T(i, 1)).ToString)
    

     

    With this method :

    -the file "resources.resx" is not growing anymore, size is near few Kb (before it was 75mb and more than 850000 lines inside....)

    -Ram used during build time is approximativly 150Mb (before it was more than 2,8Gb...and "System.OutOfMemoryException" occured)

    -VS2008 doesn't freeze anymore :)), and i can continue to use Embedded resources!

     

    I wish this little explication could help somebody. Sorry for my poor english...

    Thanks to all and specially to Poppa Mintin and Winbase.

     

    Cz

    Wednesday, September 29, 2010 5:13 PM
  • Hi All,

    In order to reproduce the memoryStream issue please check the following code.

     protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
                ClsDataDTO data = new ClsDataDTO();
                DataTable dt = new DataTable();
                dt.Columns.AddRange(
                    new DataColumn[]
                    {
                        new DataColumn(), new DataColumn(), new DataColumn(), new DataColumn(),
                        new DataColumn(), new DataColumn(), new DataColumn(), new DataColumn(),
                        new DataColumn(), new DataColumn(), new DataColumn(), new DataColumn(),
                        new DataColumn(), new DataColumn(), new DataColumn(), new DataColumn(),
                        new DataColumn(), new DataColumn(), new DataColumn(), new DataColumn()
                    });
                for (int i = 0; i < 300000; i++)
                {
                    DataRow dr = dt.NewRow();
                    for (int c = 0; c < dt.Columns.Count; c++)
                    {
                        dr[c] = Guid.NewGuid().ToString();
                    }
                    dt.Rows.Add(dr);
                }
                dt.RemotingFormat = SerializationFormat.Binary;
                
                data.MyTable = dt;
                
                byte[] byt = Serialize(data);
            }
           
            public static byte[] Serialize(object objMessage)
            {
                byte[] bytData = null;
                if (objMessage != null)
                {
                    MemoryStream msMemoryStream = new MemoryStream();
                    BinaryFormatter binBinaryFormater = new BinaryFormatter();
                    try
                    {
                        binBinaryFormater.Serialize(msMemoryStream, objMessage);
                        bytData = msMemoryStream.ToArray();
                    }
                    catch (System.Runtime.Serialization.SerializationException seex)
                    {
                        throw seex;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        msMemoryStream.Dispose();
                        binBinaryFormater = null;
                    }
                }
                else
                {
                    throw new Exception("Can not Serialize Null Object");
                }
                return bytData;
            }
    Thanks

    vinaya kumar

    Tuesday, June 5, 2012 6:09 PM
  • if u have 2 resource folders and designers, try make one of them, that worked for me
    Wednesday, March 23, 2016 1:57 PM