1

PLEASE READ THIS FIRST Please avoid tagging my question as possible duplicate of "What is a NullReferenceException and how to fix it"; I've read all of that before on some older questions. The NullReferenceException is not the main topic here, I understand where do they come from. The main topic is why am I getting this exception only on the server and not on local. Having clarified this, please read below :)

I have a form that pops-up with a button's click. There are some common controls on it; so when I run it through my local environment (visual studio's asp server) it shows fine, and even on the Page_Load I have many instructions that load the form's fields with data from a DB (it's an edit form).

But when I run it on the remote server through IIS (from a web browser) Instead of the form displaying I get a NullReferenceException.

So I started commenting instructions from my Page_Load, so I could discard possibilities, until I reached the point of having my whole Page_Load method commented, seriously the 100%, no instructions should execute here, but I'm still getting the NullReferenceException error, the stack trace looks like this:

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.] SisProEmp.editar_necesidad.Page_Load(Object sender, EventArgs e) +1645 System.Web.UI.Control.LoadRecursive() +70
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3177

"editar_necesidad" is the name of the form (the html page).

Note that this only happens when testing through the web-browser, and not on local environment. At first I thought it might have been the DateTime format of the server, but I've discarded that since, as I mentioned, the Page_Load is executing nothing right now, and I don't even get to see the rendered empty controls.

Glen Lambert
  • 33
  • 2
  • 10
  • _possible duplicate of_ [What is a NullReferenceException and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Hamid Pourjam Nov 22 '15 at 22:47
  • Nope, I am aware of what a NullReferenceException is, and I know some ways to fix them. The problem is that in this particular case the exception is thrown only when testing through the server. – Glen Lambert Nov 22 '15 at 22:49
  • This is not the first time that I see questions in SO being tagged as "duplicates" of that one you linked, but that's not a good thing, even though that question you suggest and the answers it provides are quite complete and structured, they do not cover all of the cases. So in my case I am not trying to ask "how to fix a NullReferenceException" neither what an NRE is. I just need help finding the reason of this NRE. – Glen Lambert Nov 22 '15 at 22:51
  • I could Mjölnir close this immediately but I'll leave it open because you have taken significant steps to debug this already. – usr Nov 22 '15 at 22:52
  • 1
    Delete the whole Page_Load method and run again. If it's still on the exception stack then old code is deployed. This is what I think. Also deploy PDBs so that you get files and line numbers. Always deploy PDBs anyway. – usr Nov 22 '15 at 22:53
  • 1
    The +1645 beside Page_Load is an offset into the native code. Pretty long method if you ask me, definitely not empty. – Wiktor Zychla Nov 22 '15 at 22:55
  • @usr: I could too, and frankly the only reason I haven't is in deference to your assertion that it shouldn't be. Personally, while the OP seems to have debugged, they have not provided the details of that debugging, nor have they provided a good code example. Plus, the stack trace appears to show the exception occurring in their code, which means that had they actually done _real_ debugging (not just commenting things out), they would at least know _what_ was `null` and where that value was coming from, and could ask about _that_ instead of the all-purpose "why am I getting NRE here?" – Peter Duniho Nov 22 '15 at 22:55
  • @PeterDuniho I think he's hitting the limits of his debugging skills but it's not careless. There was a day on which we would have not been able to solve this, either. – usr Nov 22 '15 at 22:58
  • @usr: perhaps he is. But that's the point of the canonical NRE Q&A. It provides useful information to people who have insufficient debugging skills to correctly diagnose such issues. Your suggestion to diagnose whether the old code is still deployed is useful, but it only in the context of the "comment out and run again" debugging technique; there are better ways to approach the problem, many of them addressed in the canonical post. Put another way: once he gets his code correctly deployed, he's still got an NRE to fix. What then? – Peter Duniho Nov 22 '15 at 23:01
  • @usr Yes, thanks for that one. You are right, this is as far as I can debug on the server, on local I can make a better effort debugging since I have the console, but the server we work on to publish things has some issues that have not been fixed yet and we do not administrate it; so I apologize if I'm not showing the best debugging skills, and thanks for not deleting my question. Wiktor Zyckla I'm not really sure what those numbers mean, but if the whole insides of the Page_Load method is commented why does that happen? – Glen Lambert Nov 22 '15 at 23:04
  • @PeterDuniho then, the dupe applies. But maybe you're right. – usr Nov 22 '15 at 23:04
  • @Glen: IMHO you should word your title and post differently, if you want to avoid someone else coming along and closing as a dupe. I'd title the question something like "Page_Load() method fails to deploy to server", and then focus on that aspect of the issue in your question. You could be getting _any_ sort of problem in the code, and the question is still about why deleting the code doesn't make the problem go away. So putting the NRE as central to the question is unwise. Your question may well still be a dupe, but at least it would get closed as a dupe of another question useful to you. :) – Peter Duniho Nov 22 '15 at 23:09
  • @GlenLambert: multiple possible reasons and apparently the method is not empty. You are not sure but have to believe, 1645 means it blows up at the offset 1645 of the native code. Double or even tripple check if the dll at the server IS the dll with commented code and the app on the server is the one you think it is and the server is the one you think you hit. – Wiktor Zychla Nov 22 '15 at 23:11
  • @PeterDuniho Alright man, I changed the title. Thought it was a good idea to mention it was an NRE. But why does it work fine on local? While on local environment I can even submit the form's data and it saves on the DB (the same remote DB as when testing on web) What happens different on the server? I mean, many things should happen differently, but what is _the one_ here that works so different that it can't even render my form with empty fields? – Glen Lambert Nov 22 '15 at 23:20

1 Answers1

0
  1. Open your dll on the web server from your web application folder with Telerik JustDecompile. It may surprise you to see that the code you think is there is not the same as the code that is actually there. There's a principle in debugging called "Stop thinking and look".

  2. Delete the cache of the web server C:\WINDOWS\Microsoft.NET\Framework\<version>\Temporary ASP.NET Files. Look for 64 bit as well.

toddmo
  • 20,682
  • 14
  • 97
  • 107
  • I already tried the second one. Stopped the application pool, deleted the temporary files and run again, but it still happens. – Glen Lambert Nov 22 '15 at 23:06
  • ok well decompile to make sure what you have and / or put response.write("hello") in the page_load as an experiment to make sure what's in your editor is live. and / or start all over with a blank page and add stuff back bit by bit, in case it's inside some subordinate control's load during load. – toddmo Nov 22 '15 at 23:11
  • What I usually do is search for the DLL name on C:, possibly using the very reliably Everything Search tool. That DLL *must* exist somewhere. Kill it everywhere, run the app to confirm that it fails to launch. – usr Nov 22 '15 at 23:27