Click here to Skip to main content
15,791,739 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
C#
private BitmapSource GetIconImage(FileInfo fileN)
       {
           try
           {
               BitmapSource result = null;
               if (fileN.Exists)
               {
                   System.Drawing.Icon ico = System.Drawing.Icon.ExtractAssociatedIcon(fileN.FullName);
                   if (ico != null)
                   {
                       using (MemoryStream strm = new MemoryStream())
                       {
                  ico.Save(strm); // throwing error in this line after 8000 files

                           strm.Seek(0, SeekOrigin.Begin);
                           IconBitmapDecoder ibd = new IconBitmapDecoder(strm, BitmapCreateOptions.None, BitmapCacheOption.Default);
                           result = ibd.Frames[0];
                       }
                       ico.Dispose();
                   }

               }
               return result;
           }
           catch (Exception exp)
           {
               Console.Out.WriteLine(exp.Message);
               return null;
           }
       }

The above function is working fine for around 8000 files filling in to TreeListView, after that limit its keep on showing exception in the Line ico.Save(strm);
Exceptions which I am getting in Output window are :
A first chance exception of type 'System.IO.FileFormatException' occurred in PresentationCore.dll
The image format is unrecognized.
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.Drawing.dll
There are no more files
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.Drawing.dll
Not enough storage is available to process this command
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.Drawing.dll
Not enough storage is available to process this command


Please help me out with this errors, How can I handle this? Is there any limit in MemoryStream?
Whether I need to change any data type?

Thanks in advance...
Posted
Updated 10-Jul-13 23:13pm
v2
Comments
Member 7686563 11-Jul-13 9:17am    
Some of the time I am getting these exception too :


A first chance exception of type 'System.NotSupportedException' occurred in PresentationCore.dll
No imaging component suitable to complete this operation was found.
A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in System.Drawing.dll
Error HRESULT E_FAIL has been returned from a call to a COM component.
Exception from HRESULT: 0x88980406
Member 7686563 11-Mar-14 9:34am    
This issue because of reaches the limit of instance objects created.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900