I have a problem with accessing values in the session through pagemethods when I try connecting to SQL Server.
I have uploadEngin.aspx page for uploading files and for monitoring the upload state I store the state value (like 10%) in session. In the uploadEngin.aspx page I am connecting to SQL Server to get the valid extension for files. I have a basic problem. Example below show a sample code:
uploadEngin:
protected void Page_Load(object sender, EventArgs e)
{
    this.Session["s"] = "hello";
    if (!IsPostBack)
    {
        admin.app.core.attachment.AttachmentType att = new app.core.attachment.AttachmentType();
        att.GetExtentionAndMainPath("Image");
    }
}
[System.Web.Services.WebMethod(EnableSession = true)]
public static String g()
{
    return HttpContext.Current.Session["s"].ToString();
}
Javascript:
(function () {
    window.onload = function () {
        PageMethods.g(function (r) { alert(r); }, function (r) {
            console.log(r);
        });
    }
})();
GetExtentionAndMainPath:
public String[] GetExtentionAndMainPath(String name)
{
    String[] ext =new String[2];
    String x = name;
    UInt64 id = FindIdByName(x);
    DataTable dt = new DataAccess().ExecuteSelect("Select_ano_attachmentType", CommandType.StoredProcedure, new DataParam("@id", id, SqlDbType.BigInt));
    if (dt.Rows.Count > 0)
    {
        ext[0] = dt.Rows[0]["attachmentType_validExtention"].ToString();
        ext[1]= dt.Rows[0]["attachmentType_mainPath"].ToString();
    }
    return ext;
}
Without code inside if(!isPostBack) everything works fine and I see the "hello" message. When I use that code however (connecting to SQL Server to get the valid extension), I get 
WebServiceError: Object reference not set to an instance of an object
How should I solve this problem?