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
280 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Curl Setup Option 4 91
Debugging web applications - in general and specifically 401 Unauthorized errors 6 38
Where can I find... 1 44
"Go Fund Me" type plugin 5 25
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

821 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