Hi there!

I have some code generated using VS.NET. I tried to run that very same
code using Mono/XSP and I got an error 500
(System.NullReferenceException) from it. Apparenly this is due to a line
where `Application["ContadorAccesos"].ToString()' is consulted before it
is initialized.

The trick here is that `Application["ContadorAccessos"]' is actually
initialized in the Global.asax.cs file (set to zero on the method
"Application_Start" of class "Global". Somehow VS.NET executes the
initialization prior to the value being consulted, while Mono/XSP does
not.

I have tried stuff like compiling the files in different ways and under
different names; none of them with success. The latest command line I
used was "mcs Global.asax.cs AssemblyInfo.cs Session.aspx.cs
-r:System.Web -r:System.Drawing -r:System.Data -t:library -o
bin/Session.aspx.dll"

The stack trace is shown at the bottom of this message, and the four
related files are attached as well. I hope you can help me understand
how to use the Global.asax(.cs) file(s) and anything else I should know
in order to be able to deploy some of my VS.NET generated code using
Mono/XSP.

Thanks for your help.


Stack Trace:

System.NullReferenceException: Object reference not set to an instance
of an object
in <0x0003d> WebAppLatam.Session:Page_Load (object,System.EventArgs)
in <0x0005a> (wrapper delegate-invoke) 
System.MulticastDelegate:invoke_void_object_EventArgs (object,System.EventArgs)
in <0x00090> System.Web.UI.Control:OnLoad (System.EventArgs)
in <0x00033> System.Web.UI.Control:LoadRecursive ()
in <0x0018b> System.Web.UI.Page:InternalProcessRequest ()
in <0x0008d> System.Web.UI.Page:ProcessRequest (System.Web.HttpContext)
in <0x00327> ExecuteHandlerState:Execute ()
in <0x0007e> StateMachine:ExecuteState (System.Web.HttpApplication/IStateHandler,bool&)




<%@ Page language="c#" Codebehind="Session.aspx.cs" AutoEventWireup="false" 
Inherits="WebAppLatam.Session" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
        <HEAD>
                <title>Session</title>
                <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
                <meta name="CODE_LANGUAGE" Content="C#">
                <meta name="vs_defaultClientScript" content="JavaScript">
                <meta name="vs_targetSchema" 
content="http://schemas.microsoft.com/intellisense/ie5";>
        </HEAD>
        <body>
                <form id="Form1" method="post" runat="server">
                        <P><FONT color="#6666ff" size="5"><STRONG>Application y 
Session</STRONG></FONT></P>
                        <P>Numero de accesos:
                                <asp:Label id="lblContador" 
runat="server"></asp:Label></P>
                        <P>
                                <asp:Button id="btnContador" runat="server" 
Text="Incrementa el contador"></asp:Button></P>
                        <P><FONT color="#cc66cc" 
size="5"><STRONG>Autenticacion</STRONG></FONT></P>
                        <P>Nombre:
                                <asp:TextBox id="txtNombre" 
runat="server"></asp:TextBox></P>
                        <P>Clave:
                                <asp:TextBox id="txtClave" 
runat="server"></asp:TextBox></P>
                        <P>
                                <asp:Button id="btnCrea" runat="server" Text="Crear 
sesion"></asp:Button>&nbsp;
                                <asp:Button id="btnLee" runat="server" Text="Leer 
sesion"></asp:Button>
                                <asp:Button id="btnAbandona" runat="server" 
Text="Abandonar sesion"></asp:Button></P>
                        <P>
                                <asp:Label id="lblSesion" 
runat="server"></asp:Label></P>
                        <P>
                                <asp:HyperLink id="HyperLink1" runat="server" 
ImageUrl="VerificaSession.aspx">Verifica Sesion</asp:HyperLink></P>
                        <P>&nbsp;</P>
                </form>
        </body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebAppLatam
{
        /// <summary>
        /// Descripción breve de Session.
        /// </summary>
        public class Session : System.Web.UI.Page
        {
                protected System.Web.UI.WebControls.Label lblContador;
                protected System.Web.UI.WebControls.Button btnContador;
                protected System.Web.UI.WebControls.TextBox txtNombre;
                protected System.Web.UI.WebControls.TextBox txtClave;
                protected System.Web.UI.WebControls.Button btnCrea;
                protected System.Web.UI.WebControls.Button btnLee;
                protected System.Web.UI.WebControls.Button btnAbandona;
                protected System.Web.UI.WebControls.Label lblSesion;
                protected System.Web.UI.WebControls.HyperLink HyperLink1;

                private void Page_Load(object sender, System.EventArgs e)
                {
                        //Console.WriteLine(Application["ContadorAccesos"].ToString());
                        // Introducir aquí el código de usuario para inicializar la 
página
                        this.lblContador.Text = 
Application["ContadorAccesos"].ToString();
                }

                #region Código generado por el Diseñador de Web Forms
                override protected void OnInit(EventArgs e)
                {
                        //
                        // CODEGEN: llamada requerida por el Diseñador de Web Forms 
ASP.NET.
                        //
                        InitializeComponent();
                        base.OnInit(e);
                }
                
                /// <summary>
                /// Método necesario para admitir el Diseñador. No se puede modificar
                /// el contenido del método con el editor de código.
                /// </summary>
                private void InitializeComponent()
                {    
                        this.btnContador.Click += new 
System.EventHandler(this.btnContador_Click);
                        this.btnCrea.Click += new 
System.EventHandler(this.btnCrea_Click);
                        this.btnLee.Click += new 
System.EventHandler(this.btnLee_Click);
                        this.btnAbandona.Click += new 
System.EventHandler(this.btnAbandona_Click);
                        this.Load += new System.EventHandler(this.Page_Load);

                }
                #endregion

                private void btnContador_Click(object sender, System.EventArgs e)
                {
                        Application.Lock();
                        Application["ContadorAccesos"] = 
Convert.ToInt64(Application["ContadorAccesos"]) + 10;
                        Application.UnLock();
                }

                private void btnCrea_Click(object sender, System.EventArgs e)
                {
                        if (this.txtNombre.Text != "" || this.txtClave.Text != "" )
                                Session["Usuario"] = this.txtNombre.Text;
                        Session["Clave"] = this.txtClave.Text;
                        this.lblSesion.Text = "Sesion creada con éxito !!!";
                }

                private void btnLee_Click(object sender, System.EventArgs e)
                {
                        this.lblSesion.Text = "Session ID: " + Session.SessionID +
                                " - Usuario: " + Session["Usuario"] + 
                                " - Clave: " + Session["Clave"];
                }

                private void btnAbandona_Click(object sender, System.EventArgs e)
                {
                        Session.Abandon();
                }
        }
}
using System; 
using System.Collections; 
using System.ComponentModel; 
using System.Web; 
using System.Web.SessionState; 

namespace WebAppLatam 
{ 
        /// <summary> 
        /// Descripción breve de Global. 
        /// </summary> 
        public class Global : System.Web.HttpApplication 
        { 
                /// <summary> 
                /// Variable del diseñador requerida. 
                /// </summary> 
                private System.ComponentModel.IContainer components = null; 

                public Global() 
                { 
                        InitializeComponent(); 
                }        
                 
                protected void Application_Start(Object sender, EventArgs e) 
                { 
                        Application["ContadorAccesos"] = 0; 
                } 
  
                protected void Session_Start(Object sender, EventArgs e) 
                { 

                } 

                protected void Application_BeginRequest(Object sender, EventArgs e) 
                { 

                } 

                protected void Application_EndRequest(Object sender, EventArgs e) 
                { 

                } 

                protected void Application_AuthenticateRequest(Object sender, 
EventArgs e) 
                { 

                } 

                protected void Application_Error(Object sender, EventArgs e) 
                { 

                } 

                protected void Session_End(Object sender, EventArgs e) 
                { 

                } 

                protected void Application_End(Object sender, EventArgs e) 
                { 

                } 
                         
                #region Código generado por el Diseñador de Web Forms 
                /// <summary> 
                /// Método necesario para admitir el Diseñador. No se puede modificar 
                /// el contenido del método con el editor de código. 
                /// </summary> 
                private void InitializeComponent() 
                {    
                        this.components = new System.ComponentModel.Container(); 
                } 
                #endregion 
        } 
} 
using System.Reflection;
using System.Runtime.CompilerServices;

//
// La información general de un ensamblado se controla mediante el siguiente 
// conjunto de atributos. Cambie estos atributos para modificar la información
// asociada con un ensamblado.
//
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]         

//
// La información de versión de un ensamblado consta de los siguientes cuatro valores:
//
//      Versión principal
//      Versión secundaria 
//      Versión de compilación
//      Revisión
//
// Puede especificar todos los valores o usar los valores predeterminados (número de 
versión de compilación y de revisión) 
// usando el símbolo '*' como se muestra a continuación:

[assembly: AssemblyVersion("1.0.*")]

//
// Si desea firmar el ensamblado, debe especificar una clave para su uso. Consulte la 
documentación de 
// Microsoft .NET Framework para obtener más información sobre la firma de ensamblados.
//
// Utilice los atributos siguientes para controlar qué clave desea utilizar para 
firmar. 
//
// Notas: 
//   (*) Si no se especifica ninguna clave, el ensamblado no se firma.
//   (*) KeyName se refiere a una clave instalada en el Proveedor de servicios
//       de cifrado (CSP) en el equipo. KeyFile se refiere a un archivo que contiene
//       una clave.
//   (*) Si se especifican los valores KeyFile y KeyName, tendrá 
//       lugar el siguiente proceso:
//       (1) Si KeyName se puede encontrar en el CSP, se utilizará dicha clave.
//       (2) Si KeyName no existe pero sí KeyFile, se instalará 
//           y utilizará la clave de KeyFile en el CSP.
//   (*) Para crear KeyFile, puede ejecutar la utilidad sn.exe (Strong Name).
//        Cuando se especifica KeyFile, la ubicación de KeyFile debe ser
//        relativa al "directorio de resultados del proyecto". La ubicación del 
directorio de resultados
//        del proyecto depende de si se está trabajando con un proyecto Web o local.
//        En proyectos locales, el directorio de resultados del proyecto se define como
//       <Directorio del proyecto>\obj\<Configuration>. Por ejemplo, si KeyFile
//       se encuentra en el directorio del proyecto, el atributo AssemblyKeyFile se 
especifica 
//       como [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
//        En proyectos Web, el directorio de resultados del proyecto se define como
//       %RUTA PRINCIPAL%\VSWebCache\<Nombre del equipo>\<Directorio del 
proyecto>\obj\<Configuración>.
//   (*) (*) Firma retardada es una opción avanzada; consulte la documentación de
//       Microsoft .NET Framework para obtener más información.
//
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

Reply via email to