Go Premium for a chance to win a PS4. Enter to Win

x
?
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
?
289 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
7 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
Cyber Threats to Small Businesses (Part 2)

The evolving cybersecurity landscape presents SMBs with a host of new threats to their clients, their data, and their bottom line. In part 2 of this blog series, learn three quick processes Webroot’s CISO, Gary Hayslip, recommends to help small businesses beat modern threats.

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

New Relic recently released its Synthetics product that allows for the creation of performance monitors that periodically test a site's performance. If you wish to test an interactive workflow New Relic employs Selenium WebDriverJS to run those test…
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 …
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

783 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