?
Solved

Why after convert App to VS2012 open from Server Error: Object reference not set to an instance of an object?

Posted on 2014-09-09
8
Medium Priority
?
284 Views
Last Modified: 2014-09-11
Hi Expert,
I recently convert an existing application (used for years without problem) from VS2008 to VS2012, it runs fine within Visual Studio, no error, and works perfict.  But when I install it to the server and run from IIS, it give be Server Error: Object reference not set to an instance of an object.  I wish I can see the error in the debug that find where is rong, but it would not happen.  How can I find where is wrong?
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:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
   RouteSales._Default.fillOrder() +38
   RouteSales._Default.Page_Load(Object sender, EventArgs e) +33
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

________________________________________
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408 
The code in the application (session values are set in login page, after login success, it redirect to this page):
    public partial class _Default : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                fillDropdown("Yes");
                fillOrder();
                lblUserName.Text = "Welcome " + Session["UserName"].ToString();

……

            }


        }
public void fillDropdown(string StartPage)
        {
            //fill the period drop down
            string sSql;
            DataSet ds = new DataSet();
            System.Data.DataTable dt = new System.Data.DataTable();
            RSHelper hp = new RSHelper();
            string Err;
            string Who = Session["UserName"].ToString();
            String Order;
            if (StartPage == "Yes")
            {
                Order = Session["DestOrder"].ToString();
            }
            else
            {
                Order = ddlOrder.SelectedValue.ToString();
            }

            sSql = RSconstants.SqlSelectDetailsPeriod + Order + RSconstants.SqlSelectDetailsPeriod1 + Order + " ORDER BY Pname DESC";
      
            ds = DataLib.SelectSql(sSql, out Err);
            if (Err != "")
            {
                lblErr.Text = Err.ToString();
            }
            else
            {
                dt = ds.Tables[0];
                ddlPeriodStart.DataSource = dt;
                ddlPeriodStart.DataTextField = "Pvalue";
                ddlPeriodStart.DataValueField = "Pvalue";
                ddlPeriodStart.DataBind();

                ddlPeriodEnd.DataSource = dt;
                ddlPeriodEnd.DataTextField = "Pvalue";
                ddlPeriodEnd.DataValueField = "Pvalue";
                ddlPeriodEnd.DataBind();

            }
         


        }

        private void fillOrder()
        {
            //fill the order drop down
            string Order2 = Session["DestOrder2"].ToString();
            if (Order2 == "0")
            {
                lblOrder.Visible = false;
                ddlOrder.Visible = false;
            }
            else
            {

                ddlOrder.Items.Add(Session["DestOrder"].ToString());
                ddlOrder.Items.Add(Session["DestOrder2"].ToString());
                if (Session["DestOrder3"].ToString() != "0")
                {
                    ddlOrder.Items.Add(Session["DestOrder3"].ToString());
                }
                lblOrder.Visible = true;
                ddlOrder.Visible = true;

            }
        }

Open in new window


Thanks.
0
Comment
Question by:fedmilk1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40312913
Was the code .NET4 compiled before?
Are all dependancies installed on the server?
0
 
LVL 37

Accepted Solution

by:
Neil Russell earned 2000 total points
ID: 40312918
it would also help if you had some error checking in your code to catch exception.   I dont see a single try in all that code.
0
 

Author Comment

by:fedmilk1
ID: 40314504
Thanks Neilsr!
I added try catch blocks and find anywhere has the Session give me this error.
I wonder why the Sessions not working anymore.
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

Author Comment

by:fedmilk1
ID: 40315846
I've requested that this question be closed as follows:

Accepted answer: 0 points for fedmilk1's comment #a40314504

for the following reason:

I added try catch blocks and find anywhere has the Session give me this error.
0
 

Author Comment

by:fedmilk1
ID: 40315714
I added try catch blocks and find anywhere has the Session give me this error.
0
 

Author Comment

by:fedmilk1
ID: 40315716
yyyyy
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40315847
Your question was  " How can I find where is wrong? "

I explained how you should add Try Catch to your code and this has indeed shown you that the problem is with your session object, clearly answering the question of " How can I find where is wrong? "
0

Featured Post

Automating Your MSP Business

The road to profitability.
Delivering superior services is key to ensuring customer satisfaction and the consequent long-term relationships that enable MSPs to lock in predictable, recurring revenue. What's the best way to deliver superior service? One word: automation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

To properly understand GitHub, let’s divide it into two words ‘Git’ and ‘Hub’. Git is basically a ‘Distribution Version Control’ (DVC) and ‘Source Code Management’ (SCM) system widely used by software programmers while Hub means the efficient centre…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question