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
282 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 500 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

The task of choosing a web design company to build a website for your business should never be taken in a light manner. Provided the fact that your website will act as a representative to your business and will be responsible for imposing an online …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

623 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