views:

183

answers:

3

Hi, I have a website written using ASP.NET. We have a development machine and a deployment server.
The site works great on the development machine, but when is transfered (using simple FTP Upload) generates strange behavior. It starts working just fine, but after a while stops working and throws an exception "Exception: Object reference not set to an instance of an object.".
The deal is that the absolute path of the website on the development machine is different than on the deployment server (and why should they be similar?) and the exact error is:

Exception: Object reference not set to an instance of an object. at SOMEPROJECT_Objects.Player..ctor(Int32 PlayerID) in C:\inetpub\wwwroot\SOMEPROJECTSolution\ALLPROJECT\SOMEPROJECT_Objects\Player.cs:line 123 at SOMEPROJECT_GameLayer.M_Game.PlayerActiveGame(Int32 PlayerID) in C:\inetpub\wwwroot\SOMEPROJECTSolution\ALLPROJECT\SOMEPROJECT_GameLayer\M_Game.cs:line 85 at Web.getsms.Page_Load(Object sender, EventArgs e) in C:\inetpub\wwwroot\SOMEPROJECTSolution\ALLPROJECT\SOMEPROJECT-sms\Web\getsms.aspx.cs:line 59

The address that it is looking for is the address on the DEVELOPMENT machine, where as the site now resides on the deployment server.

Any ideas why this happens would be appreciated.

Thanks, Roman

A: 

Unfortunately we're not going to be able to help much at this point until you post the relevant code.

You don't need to worry about the path though. That path is only being shown because you built the assembly on your dev machine and then moved it to the server. It happens quite frequently. It's not the source of your issue.

Justin Niessner
ohh... So the path is NOT real? the problem is in the code itself?
Roman
It is very strange - if I use the SAME code using VS debug - it works. If I run the code using the actual address - I get this exception.Strange - any ideas?
Roman
Not withotu seeing the code unfortunately.
Justin Niessner
very simple: SqlParameter[] Par = new SqlParameter[1]; Par[0] = new SqlParameter("@PlayerID", SqlDbType.Int); Par[0].Value = PlayerID; SqlDataReader dr = Dal.GetReader("SP_Get_Player", Par); if (dr.Read()) ...Breaks on the "dr.read()"
Roman
and as I said - works using the inner VS Web Server but not using the IIS
Roman
+1  A: 

It is correctly telling you where to find the problem in the source code in the location it was last compiled from. You don't normally deploy all of your source to a production machine.

Go back to the development machine and examine the lines of code it is pointing to, and you should be able to determine which object is null that it is complaining about.

RedFilter
we tried Publishing it using VS2010 - still the same problem.It looks for the source files on the development machine for some reason, and not on the current machine.
Roman
As we've said, the path is only for your information to aid in debugging. It is not the actual error. The actual error is that an object reference is null. And that error is coming from Player.cs line 123.
rchern
Oh... I see. Going to check that one :) thanks
Roman
A: 

I have exactly the same problem! Is there any solution yet?

[NullReferenceException: Object reference not set to an instance of an object.]
   ProjectManager.normal.Page_Load(Object sender, EventArgs e) in D:\User\Projects\ProjectManager\ProjectManager\normal.Master.cs:35
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +24
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +41
   System.Web.UI.Control.OnLoad(EventArgs e) +131
   System.Web.UI.Control.LoadRecursive() +65
   System.Web.UI.Control.LoadRecursive() +190
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2427

This error occurs only when "published"...

The code says:

using System;

using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using MySql.Data.MySqlClient;

namespace ProjectManager { public partial class normal : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) {

        if (!IsPostBack)
        {
            cbYear.Items.Add(System.DateTime.Now.Year.ToString());
            cbYear.Items.Add(System.DateTime.Now.AddYears(1).Year.ToString());
            cbYear.SelectedItem = cbYear.Items[cbYear.Items.IndexOfText(System.DateTime.Now.Year.ToString())];
            Session["year"] = cbYear.SelectedItem.Text.ToString();

        }
        else
        {
            Session["year"] = cbYear.SelectedItem.Text.ToString();
        }
        lName.Text = Session["username"].ToString();
        if (Convert.ToInt32(Session["admin"]) == 1)
        {
            ASPxMenu1.Visible = true;
        }
        else
        {
            ASPxMenu1.Visible = false;
        }
    }

    protected void cbYear_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}

}

Line 35 is:

lName.Text = Session["username"].ToString();

Solutions please! ;-)

Dominik
Hi, Our problem was connection object not being released properly and thus under "stressful" conditions the code broke.You should look for problems in the code. It's not a .NET problem but a programming one ;)As for your problem - it seems that the Session key "username" is empty and thus can't be converted to string. Try using String.IsNotNullOrEmpty on the Session["username"] and then trying to convert it to string.
Roman