Yesterday I was getting a NullReferenceException in my asp .net 2.0 web app. I couldn't figure out what was going wrong and at the end of my work day I decided to give up for the day, get some rest and come back to the problem and actually trace through my code and find where it broke.. Today (next day) I launch the web app and the problem is gone.
I know that it was pointing to a Page_Load in my code for the initial page (Default.aspx).
I guess I'm just kinda wondering how that happens? I know that when I started getting the exception I was really stumped because there were no code changes made or published to the server so that was the first thing that grabbed my attention and made me think that there was a problem with the server-client connection.
Anyways, no biggie if there isn't an answer out there, just kinda seemed silly. Sorry that I can't provide more details but I can't trace down the problem now. If it occurs again I'll be sure to trace the exception down in the code to exactly which line breaks it.
Maybe the reason why the exception was happening was because a correct value has been placed into an object? That error just doesn't go away by itself. NullReferenceException is common if you don't test for things like:
if (myObj != null)
//ok to assign
else
//not so ok handle it
So maybe from the time that you went and got rest and came back the following day a valid value was placed where this exception was occurring. But this exception can be thrown from anywhere, are you tapping into some sort of database?
Are you reading column data that should not be nullable?
Are you trying to access .ToString() on a null object, etc etc.
Hundreds of reasons.....
Related
I am taking over an ASP.NET MVC application from someone who left. The application was developed using .NET Framework4.
Everything was working fine, until an automatic security update was pushed to the system.
Basically, the following statement now throws a NULL exception after the push of KB4024848:
object obj = typeof(HttpRuntime).GetProperty("CacheInternal",BindingFlags.NonPublic|BindingFlags.Static).GetValue(null,null);
Looks like the key string "cacheInternal" is not recognized anymore.
Rollback of KB4024848 would make the statement work again.
Any idea about this issue, as well as what could be an alternative solution to get the same object value? (This statement is part of a section of code trying to get a list of active sessions, using InProcSessionState.)
Your solution to this question will be greatly appreciated, since we have been spending quite sometime to work on it.
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.
Just wondering if any one might now how to fix this issue.
Every part of the databroker is created and also all the database connectivity is functional.
But once we try to place them together we come up with a error saying cannot create Null Databroker.
The thing that is really strange is that we have databrokers that are basicly the exact same working.
Can any one shine some light on this issue?
We worked on this together today. We did three things to troubleshoot and fix the problem:
we changed the calling workflow so that the dataset is refreshed inside the show-screen tags (previously, this was done before the screen was called).
we refreshed the dataset (a H2 db) and connected the database (before, it showed as pool not open)
we changed the database name to main
It is working now.
"Null databroker" suggests that the broker was not created correctly, although it doesn't look like that was the case since you don't mention having to modify it to get it to work.
In these cases it can be useful to look at the error logs through the admin app to see if there are errors being thrown at some time other than compile time.
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...
See code below, for some reason it only works when I put a breakpoint on line 2 (*) is there some delay? Is it starting the next line before it finishes the 2nd one?
dp.SSLCertStoreType = nsoftware.IBizPayPal.DirectpaymentSSLCertStoreTypes.sstPEMKey
*dp.SSLCertStore = My.Computer.FileSystem.ReadAllText(Server.MapPath("\cert_key_pem.txt"))
dp.SSLCertSubject = "*"
Note: The error is thrown on the 3rd line only when the breakpoint is set on the 2nd line, after releasing the break the program executes my paypal purchase via credit card.
I will post the error again I am replicating it now...
System error: Could not acquire security credentials: error 8009030E.
There it is, while it should say "Order Confirmed!" type message if working correctly.
Almost certainly a threading issue, but nobody is going to be able to answer definitively unless they're familiar with nsoftware.IBizPayPal
Sometimes you can find that breaking can mutate an object's state, due to the locals window evaluating object properties. If they have a side-effect, then all bets are off, unfortunately :( No idea whether this is happening in your case.
I have no knowledge of ASP, so just wondering aloud: Could this be due to multithreading? You know when you put a break point you sort of freeze execution of all threads, but not so in the real execution.