.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

PathGradientBrush throwing OutOfMemory exception

Posted By:      Posted Date: August 31, 2010    Points: 0   Category :Windows Application
Hi, I don't know why I'm getting an OutOfMemoryException whil trying to create a PathGradientBrush. Here is my code:   Code Block GraphicsPath gp; PathGradientBrush pgb; Rectangle rec;   rec = new Rectangle(new Point(35, 35), new Size(60, 60));   Point[] pontos = new Point[6]; pontos[0] = new Point(rec.Left, rec.Bottom); pontos[1] = new Point(rec.Left, rec.Top - 2); pontos[2] = new Point(rec.Left + 2, rec.Top); pontos[3] = new Point(rec.Right - 2, rec.Top); pontos[4] = new Point(rec.Right, rec.Top + 2); pontos[5] = new Point(rec.Right, rec.Bottom);   byte[] pontosTipo = new byte[6]; pontosTipo[0] = (byte)PathPointType.Start; pontosTipo[1] = (byte)PathPointType.Line; pontosTipo[2] = (byte)PathPointType.Bezier; pontosTipo[3] = (byte)PathPointType.Line; pontosTipo[4] = (byte)PathPointType.Bezier; pontosTipo[5] = (byte)PathPointType.Line;   gp = new GraphicsPath(pontos, pontosTipo); pgb = new PathGradientBrush(gp); // OutOfMemoryException pgb.SurroundColors = new Color[] { Color.White, Color.Blue };     This code was running in the Paint event, and then I passed to the constructor. Still, the out of memory exception keeps throwing. I have no Idea why this is happening. It is an empty form. Any ideas on why this is happening?   Thanks for any help, Regards, Fábio

View Complete Post

More Related Resource Links

WPF textbox throwing OutOfMemory exception...



I am using a texbox in my appication to capture the log. But when I reach a certain point, it throws a system.outofmemory exception and crashes the app. How can I handle such a situation. I really need to show all the contents to the user as I cannot remove older contents. Is it possible that I save some of the older lines to a temp file? If yes, how do I do it and also at the end I should be able to hit a Save Button to Save all the contents to a text file at the specified location. So if I am transfering contents of the textbox to a temp file then how do I combine the whole log (from the temp file as well as the textbox) and save it to this new file? Also is it possible to remove the temp file everytime the OS is restarted?? 

Any help will be greatly appreciated.


Error Handling: Throwing Custom Exception Types from a Managed COM+ Server Application


Exception handling semantics in .NET are based on type, so you can create custom exceptions that have their own properties and methods. In .NET, exceptions are first-class citizens, and since they're the built-in error handling mechanism, all .NET-compliant languages must support exceptions. In addition, COM+ services are available to .NET code as Enterprise Services, so you can leverage exceptions in your Enterprise Services design.In this article the author describes custom exceptions, throwing exceptions across COM interop boundaries, and working with Enterprise Services.

Bob DeRemer

MSDN Magazine March 2004

'System OutOfMemory Exception' while using rdlc in Windows application

hi Everyone , I am Using Reporting Service (.rdlc) in my Windows application , i am getting Error System OutOfMemory Exception Like "an error occured during local report processing An Unexpected error occured in Report Processing Exception of type 'System OutOfMemory Exception'Was Thrown " what to do Please anyone help me ... Advance Thanks Anilmarnal

WCF Service stops after throwing a unhandled exception :no user is logged on.

Hi All,       I have written a WCF service which is hosted as a Managed windows service. I consume this service in a web application. The service is built using a httpBasicBinding and security Mode ="none". I'm now getting the following exception, after which the service stops  "An unhandled exception ('System.ComponentModel.Win32Exception') occurred in CMMonitorService.exe [1812]. Just-In-Time debugging this exception failed with the following error: Debugger could not be started because no user is logged on." I had tried changing the security mode to Transport/Message. with windows credential then I get a access to the path denied error. Can anyone provide hint on what am I missing and what would be the appropriate security mode and client credential to use along with basichttpBinding?

OutOfMemory Exception on 64 bit machines (Interop Problem)

Hello Our application needs to display the printer settings dialog. This works fine in 32bit windows systems, but results in a System.OutOfMemoryException at System.Runtime.InteropServices.Marshal.AllocHGlobal(IntPtr cb) when it is running under 64bit (Windows 2008 Server). The problem can easily be reproduced in a winform app. You need to set the platform target to x86 to experience the problem.Unfortuantely, our application needs to be built fox x86 for other reasons. Any ideas why this happens? Kind Regards Mat Source Code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Drawing.Printing; using System.Runtime.InteropServices; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication8 {     public partial class Form1 : Form     {         [DllImport("kernel32.dll")]         static extern IntPtr GlobalLock(IntPtr hMem);         [DllImport("kernel32.dll")]         [return: MarshalAs(UnmanagedType.Bool)]         static extern bool GlobalUnlock(IntPtr hMem);         [DllImport("kernel32.dll")]   &n

Enum in WCF is throwing exception

wcf service method is returning a datacontract that contains an enum .The following error is thrown in the clientSystem.ServiceModel.CommunicationException was caught  Message="An error occurred while receiving the HTTP response to http://localhost:8731/Design_Time_Addresses/WCFTest3/Service1/. This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details."  Source="mscorlib"  StackTrace:    Server stack trace:        at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)       at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)       at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.RequestClientReliableChannelBinder`1.OnRequest(TRequestChannel channel, Message message, TimeSpan timeout, MaskingMode maskingMode)       at System.ServiceModel.Channels.ClientReliableChannelBinder`1.Request(Message message, TimeSpan timeout, MaskingMode maskingMode)       at System.ServiceModel.Channels.ClientReliableChannelBind

WCF: Problem throwing FaultException after touching Exception.Data collection



My client code receives a CommunicationException if my server code touches the Exception.Data collection.  If my server code avoids the Exception.Data collection, then my client code works (i.e. it receives my custom exception as expected). 


I have reduced this problem down to two simple examples (see below)..one that works (A), one that does not (B).  The only difference between the two examples is that in example B, the code looks at the Exception.Data.Count property.


Why would touching the Exception.Data collection cause my client code to receive the CommunicationException? 

Is there any way to avoid this?


Thank you in advance for an consideration you may give to this question. 


A: Working Example: Client Receives CustomException
  throw new CustomException("This is a custom exception.");
 catch (CustomException ex)
  throw new FaultException<CustomException>(ex, new FaultReason(ex.Message), new FaultCode("Receiver"));


B: Non-working Example: Clien

Error System.outofMemory Exception


Dear All,

i want to ask about Analysis service.

i have a web application that display an OLAP Service.. My Analysis service spesification : Windows 2008 Data center R2 64 bit, SQL 2008 R2 memory 8giga.

when i drill down a dimension it shows an error System.OutOfMemory.Exception.. Actually the memory of my computer still remain 1.5 Giga.. Already use 6,5 giga.


Is there any solution for this Error ?


Aditya Christian

issues with Microsoft.Office.Interop.Excel in asp.net throwing Exception from HRESULT: 0x800A03EC


i m using Microsoft.Office.Interop.Excel in asp.net for Excel file as anEmail attachment .

i get the data and write to Excel but when i try to save like:

oWB.SaveAs(strCurrentDir +strFile, Microsoft.Office.Interop.Excel.


XlFileFormat.xlWorkbookNormal, null,

WorkflowRuntime.CreateWorkflow => Throwing Exception

 I am getting following exception from WorkfolwRuntime ..........
System.ArgumentException: An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Workflow.Runtime.TrackingListenerFactory.WorkflowExecutorInitializing(Object sender, WorkflowExecutorInitializingEventArgs e)
   at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
   at System.Workflow.Runtime.WorkflowRuntime.WorkflowExecutorCreated(WorkflowExecutor workflowExecutor, Boolean loaded)
   at System.Workflow.Runtime.WorkflowExecutor.RegisterWithRuntime(WorkflowRuntime workflowRuntime)
   at System.Workflow.Runtime.WorkflowRuntime.RegisterExecutor(Boolean isActivation, WorkflowExecutor executor)
   at System.Workflow.Runtime.WorkflowRuntime.Load(Guid key, CreationContext context, WorkflowInstance workflowInstance)
   at System.Workflow.Runtime.WorkflowRuntime.GetWorkflowExecutor(Guid instanceId, CreationContext context)
   at System.Workflow.Runtime.WorkflowRuntime.Intern

Infopath System.OutOfMemory Exception when try to upload larger files


I am getting “System.outOfMemory” exception when we are trying to upload 40 MB file into InfoPath Browser Form. I have already tried following methods but of no use. Any recommendation to fix the issue??


1.       Have increased upload limits for Web Application level

2.       Have increased Connection time out in IIS



Every self-respected programmer should include exception handling techniques. Sometimes your application will generate an error. Regardless of who was responsible for this error, the programmer or the user, it is up to the first to include the necessary exception handling techniques to keep his/her program from crashing. The .Net environment provides useful techniques for avoiding disastrous errors such as try-catch statements and user-defined exceptions.

Global Exception Handling with ASP.NET

After your global exception handler has done its work, you'll want to redirect the users of your website to a friendly page that tells them that something has gone wrong, and then provide them with customer support information as well as a link back to your web application's home page.

SQL Server 2005 Try and Catch Exception Handling

I'm pretty excited to see that there is some real error handling for T-SQL code in SQL Server 2005. It's pretty painful to have your wonderfully architected .NET solution tainted by less-than-VBScript error handling for stored procedures in the database. The big difference being the addition of TRY..CATCH blocks. Let's take a look:

reader.getordinal("column_may_not_exist") how to catch the exception?



would any body please help me to catch the exception if the column doesnot exist as my table columns are not static.

sometimes its throwing me indexoutofrange exception as the column doesnot exist

thanks for the help guys

Error while using exception handling block el 4.1


Hi Folks,


i am trying to use tyhe exception handling block of Enterprise library 4.1.


I just createda polisy and used IndexOutOfRangeException and added a replace handler and a logging handler to it.

I am using the NotifyRethrow PostHandlingAction to the exception.


During runtime I am getting an exception on the HandleException event, The exception is added below:



Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 42:             catch (Exception ex)
Line 43:             {
Line 44:                 bool reThrow = ExceptionPolicy.HandleException(ex, "ReplacePolicy");
Line 45:         

userprincipal.changepassword throws exception


Hi all,

      userprincipal.changepassword(oldpassword, newpassword);

gives error: that is Configuration information could not be read from the domain controller, either because the machine is unavailable, or access has been denied. (Exception from HRESULT: 0x80070547)

but userDirectoryEntry.invoke("ChangePassword", new object[] { oldpassword, newpassword });

      userDirectoryEntry.CommitChanges works fine.

Any one please tell me the reason behind this.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend