System.Web.UI.Control.LoadRecursive() - Insufficient stack to continue executing the program safely. - asp.net

I have an ASP.NET web application developed in C# and .Net v4. When you login in and leave for the page for some 15-20 minutes, I get the "Insufficient stack to continue executing the program safely."
According to my knowledge, there is no way you can try-catch the stackoverflow in .Net. I would imagine that recursive loading of web page and active session checking leading to this error (maybe a bad coding practice). I have also added the screenshot as i am able to figure it out from Stack trace. If anyone help me in this,it will be helpful.

I think I have found the solution. Still the test. Check this Link and this
they really looks promising. I will keep you guys updated when I succeed..
Thank you all for your help.

The problem is this callstack is right at the end of the stack.
A few things to look for:
Is there anywhere in your code where you are using .FindControl(string id)?
If so, is it locating a control and then trying to locate it further?
Are you dynamically creating controls, like for <asp:Placeholder/> controls.
It can be recursive when you reference the parent from within a nested control, which then gets re-referenced by the parent.

Related

Easy way to implement universal error handling in ASP.Net application

Folks,
I have an application that is primarily one page with a lot of user controls and custom controls. ASP.Net WebParts are being used. There is almost no code in the web page and its master page: it's all in various components.
The design requirements include an error message display panel. The client would like the app to display any errors occurring in any part of the app on the error message display rather than going to a custom error page. (This was a recent decision: when we started we were thinking custom error page.)
As far as I can tell, WebParts don't provide any default error handling (no capture of errors and displaying of messages) and user controls don't necessarily fire their OnError event when an internal error occurs.
So I'm looking at wrapping absolutely everything in Try ... Catch blocks, at least at the presentation level, and doing the handling. So my question is: is there any easy way to implement a kind of global, or at least class-wide, error handler, that will handle an error in the way I choose, interrupt the routine that was executing, but return (after handling) to the caller of the method that failed?
I'm willing to adapt code to verify that subroutines did what they were supposed to and returned appropriate values (ex: non-null data objects.) What I don't want is for the whole process to be aborted up to the very top, with rendering skipped, or (of course) the famous yellow and white screen.
I guess this is a case for aspect-oriented programming, but I don't think ASP.Net provides anything like that yet. I didn't get the impression that EntLib 5.0 did, either.
I would adore it if it were possible to decorate a method with an attribute that meant "On error call such-and-such a static method of such-and-such a class". But I doubt it is, yet.
Any suggestions are welcome.
Thanks,
Ann L.
For starters, it's bad practice to put Try Catch handlers around every piece of code in your application. There is a slight performance hit every time you set that up, and this could slow things down really fast.
In your Global.asax.cs (or .vb) file, there is a method in there called Application_Error which is the global error handler. This will catch any error you haven't previously caught (or thrown up) within the application.
You could easily put your error handling code here. It could be as simple as dumping the error message to a log for future review, or check for the exception type (SQL vs. File vs. HTTP) and do the error handling task related to the type.
You need to take a look at elmah. If you google 'elmah' it has an error module/handler that does pretty much what you are looking for (although it will take some extra tweaking..)
You might want to consider letting your errors 'bubble up' though.. There are some serious performance issues with writing a bunch of Try..Catch..Finally blocks...

Exploring a ASP.NET website's code

I have been set a new project at work and have been given the code beforehand to give it a good look. Since time is limited, can anyone please give me the best way to get a good feel of the project. What are the things I should be looking for within the code?
Thanks.
Well, first I'd get the app running and get a sense of the functionality (the business functionality) of the application. If you're not familiar with the business functionality, keep notes on your questions.
Next examine the code. things like:
1. Database access methodology (ASP.NET Core, Linq2SQL, EF, NHibernate etc.)
2. Take a look at the database and the data model
3. Examine the areas you're not comfortable with in regards the ASP.NET/C# etc.
Keep a note of questions you have through this phase. If they want you to hit the ground running, you'll need your questions answered. Asking the right (intelligent) questions shows you've spent time examining the code (as they would expect)
Set a breakpoint at the page_load or init event handler of a page of interest and step through the code (F11) to see where it goes and what it does.

ASP.NET Long Process and Sending updates to Browser

I've asked this before but I was hoping for another answer and perhaps some code samples because I've been having a difficult time with this. I have an asp.net page. The user hits the "Run" button and I have code IN AN ASSEMBLY, not in the APP_CODE folder that is called and runs a long process that moves product info from a file into the database. While the user waits, I would like them to see status updates like what product the import process in on and status info. I'm assuming I'd break off into another thread and use Ajax but I have no idea how to do this. Some code samples would be very helpful, thanks.
A simpler way to do this without needing to go into multi threading (which can cause all sorts of nasty, hard to track down bugs) is to use AsyncResults in .NET and AJAX which allow you to query a process.
A good example to start you off can be found here.
found it by using HttpResponse.Flush

InfoPath FormControl on STA worker thread

I have a .NET class that exposes two public methods: one to create an InfoPath form and another to Export to one of the supported formats. I’m using the Microsoft FormControl to do this. It’s hosted by a Form that does not get displayed. I get called by a Winforms app, but on an MTA worker thread instead of the UI thread. So I create an STA thread and execute on that, which works exactly once and then results in this exception:
System.InvalidOperationException was unhandled
Message="Unable to get the window handle for the 'FormControl' control. Windowless ActiveX controls are not supported."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.AxHost.EnsureWindowPresent()
at System.Windows.Forms.AxHost.InPlaceActivate()
at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state)
at System.Windows.Forms.AxHost.CreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.AxHost.EndInit()
at InfoPathCreateStaThreadTest.FormControlHost.InitializeComponent() in C:\Windows\Temp\InfoPathCreateStaThreadTest\InfoPathCreateStaThreadTest\FormControlHost.Designer.cs:line 65
After some experimenting, I started to suspect this is a message pumping problem. I then came across this, which makes me more strongly suspect so: http://blogs.msdn.com/cbrumme/archive/2004/02/02/66219.aspx
I tried various methods of pumping messages with no luck. I should mention that the alternative of automating the InfoPath app is not viable unless I can figure out how to hide the app.
Any help would be much appreciated.
Are you creating your worker thread (the one calling the control) after the form is loaded? I was having this problem until I moved all of my calls to the FormControl within the Load event of the parent form. Since doing that I have not come across this specific error (though I have seen many others)
I'm researching the same error and found this: http://social.msdn.microsoft.com/Forums/en-US/clr/thread/9c36e5d3-a75c-4760-9070-5dbaf188992b/ which attributes the problem to DEP being unexpectedly turned on and provides a fix. I don't know yet if this will solve my problem.
Thanks for your reply. Sorry for the long delayed reply on my end. DEP is not causing the problem for me. I ended up automating the InfoPath app vs. using the FormControl. Best of luck getting your issue resolved!
Rob

Looking for a simple explanation on using trace logging

I have seen several projects that use the Trace functionality to capture events and stream them out to a log file. I have been unsuccessful in finding a simple to follow guide that will show me how to configure Trace to capture and write said logfile. Does anyone have a link recommendations, or provide some simple steps to follow?
The Trace object writes the statements to any attached TraceListeners. You can build your own, but there are a number already defined in the System.Diagnostics namespace, including:
ConsoleTraceListener (Console)
DefaultTraceListener (Visual Studio / Debugger)
DelimitedListTraceListener (TextWriter, special formatting)
EventLogTraceListener (EventLog - anything that inherits from System.Diagnostics.EventLog)
TextWriterTraceListener (TextWriter - think file)
You can, of course, inherit your own from the TraceListener class that writes to where ever you want. For example, you could log to a database, have it send e-mails or pages in certain situations, or write the statements back to a logging platform like log4net.
The big thing is that you need to create an instance of whatever listeners you want and then add them to the Trace' class Listeners collection. You can add as many as you need and Trace will write to all of them. This way, you can write your logging code once using a well-supported and understood object that's part of the framework, and you can attach anything you need to it.
I stumbled into a MSDN article that really helps. Sorry I didn't find it before posting the question but perhaps others may have the same question and haven't found this link.
Take a look at logging frameworks. We rolled out own, but are now migrating over to log4net available free at http://logging.apache.org/log4net/
Im looking for a way to set the Category of the EventLog, the FormattedEventLogTraceListener writes into (not the category of the message).
But I can't find an appropriate property of this class.
Is it possible to set this?

Resources