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
271 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
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…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

759 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now