Object reference not set to an instance of an object.
-
Hi guys, I have the above exception that appears to me when executing my code:
protected void Page_Load (object sender, EventArgs e)
{
//Génération du fichier XML.
if (this.Request ["ActionButton"] == "Generate")
{
string Json = "";
// Initiation de la collection
SLSalariesCollection salaries = new SLSalariesCollection (this._Session);
salaries.Init ();
// Création du fichier xml.
string fileName = @"D:\New Folder\MyXmlff.xml";
// Si le fichier existe effacer,
if (System.IO.File.Exists (fileName))
{
System.IO.File.Delete (fileName);
}
XmlTextWriter myXmlTextWriter = new XmlTextWriter ("D:/New Folder/MyXmlff.xml",System.Text.Encoding.UTF8);
myXmlTextWriter.Formatting = Formatting.Indented;
myXmlTextWriter.WriteStartDocument(false);
myXmlTextWriter.WriteStartElement("root");
myXmlTextWriter.WriteAttributeString("xmlns","urn:iso:std:iso:20022:tech:xsd:pain.001.001.02");
myXmlTextWriter.WriteStartElement("pain.001.001.02");
int j = 0;
// Récupérer la date d'Aujourd'huit de virement.
DateTime Now = DateTime.UtcNow;
string datevir = Now.ToString();
// Attribut Batch booking
Boolean batch = true;
//formatter la collection de salariés.
foreach (SLSalarie salari in salaries)
{
j++;
Json = Json + "{succeed : 1}";
myXmlTextWriter.WriteStartElement("Salarié", salari.Matricule);} myXmlTextWriter.Flush(); myXmlTextWriter.WriteEndElement(); myXmlTextWriter.WriteEndElement(); myXmlTextWriter.Close(); this.Response.ClearContent(); this.Response.Write(Json); this.Response.End(); }
the problem that the code is sometimes excuting very well,sometimes no and appear to me this fatal EXCEPTION. I think that it is problem of refreshing my references.i did this.The first time, ok running very well,the second time EXCEPTION appears. when doing breakpoints,the problem appears in the collection'initiation.How can I solve that? also when reading about the class xmltextwriter,i know that i should treat that in my code c#.So do i should to add to my code to solve that? Thank u very much for u help hugs
Where does the exception happen? The message should tell you which line...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
-
Hi guys, I have the above exception that appears to me when executing my code:
protected void Page_Load (object sender, EventArgs e)
{
//Génération du fichier XML.
if (this.Request ["ActionButton"] == "Generate")
{
string Json = "";
// Initiation de la collection
SLSalariesCollection salaries = new SLSalariesCollection (this._Session);
salaries.Init ();
// Création du fichier xml.
string fileName = @"D:\New Folder\MyXmlff.xml";
// Si le fichier existe effacer,
if (System.IO.File.Exists (fileName))
{
System.IO.File.Delete (fileName);
}
XmlTextWriter myXmlTextWriter = new XmlTextWriter ("D:/New Folder/MyXmlff.xml",System.Text.Encoding.UTF8);
myXmlTextWriter.Formatting = Formatting.Indented;
myXmlTextWriter.WriteStartDocument(false);
myXmlTextWriter.WriteStartElement("root");
myXmlTextWriter.WriteAttributeString("xmlns","urn:iso:std:iso:20022:tech:xsd:pain.001.001.02");
myXmlTextWriter.WriteStartElement("pain.001.001.02");
int j = 0;
// Récupérer la date d'Aujourd'huit de virement.
DateTime Now = DateTime.UtcNow;
string datevir = Now.ToString();
// Attribut Batch booking
Boolean batch = true;
//formatter la collection de salariés.
foreach (SLSalarie salari in salaries)
{
j++;
Json = Json + "{succeed : 1}";
myXmlTextWriter.WriteStartElement("Salarié", salari.Matricule);} myXmlTextWriter.Flush(); myXmlTextWriter.WriteEndElement(); myXmlTextWriter.WriteEndElement(); myXmlTextWriter.Close(); this.Response.ClearContent(); this.Response.Write(Json); this.Response.End(); }
the problem that the code is sometimes excuting very well,sometimes no and appear to me this fatal EXCEPTION. I think that it is problem of refreshing my references.i did this.The first time, ok running very well,the second time EXCEPTION appears. when doing breakpoints,the problem appears in the collection'initiation.How can I solve that? also when reading about the class xmltextwriter,i know that i should treat that in my code c#.So do i should to add to my code to solve that? Thank u very much for u help hugs
-
Where does the exception happen? The message should tell you which line...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
Hello, The exception appears when initiating my collection always:
SLSalariesCollection salariers = new SLSalariesCollection (this._Session);
salariers.Init ();also xmltextwriter,as I read in msdn it provides also an exception but i don't know how to treat it ty
-
Hello, The exception appears when initiating my collection always:
SLSalariesCollection salariers = new SLSalariesCollection (this._Session);
salariers.Init ();also xmltextwriter,as I read in msdn it provides also an exception but i don't know how to treat it ty
Then either the problem is in the constructor (which you don't show) or in the _Session class variable. We would need the code for the constructor and / or the variable load.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
-
Pierre besquent wrote:
the problem appears in the collection'initiation
Then show us the collection constructor (and/or maybe its
Init
method) and show us when you create the_Session
object.Hi, I create a class library for my application that contains (_Session). Tha init method is very good built not have matter.It is seems in xmltextwriter exception
-
Then either the problem is in the constructor (which you don't show) or in the _Session class variable. We would need the code for the constructor and / or the variable load.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
hi, this is the code of my load :
protected override void OnLoad (EventArgs e)
{
try
{
// Ne pas inclure la page dans le cache client (Par défaut).
_ApplyCacheStrategy ();
// Titre.
string pageTitle = this.PageTitle;if (pageTitle != null && ( this.Title == null || this.Title == this.SessionData.PageTitleToOverride)) { this.Title = pageTitle; } // Inclure le script pour la vérification des erreurs coté serveur. \_AddCheckServerErrorScript (); // Inclure le script pour la gestion des erreurs coté client. \_AddJsReportingScript (); // Avoir le jeton de l'application racine. if (this.RootToken == null) this.RootToken = \_GetRootToken (); // Fixer la tâche en cours. this.\_PageTask = new WEAppPageTask (this.PageTaskString); // Vérifier l'accès à la page. WEAppPageAccess pageAccess; // Récupérer en cours de la page - Récupération 1. pageAccess = GetAccess (); // Vérifier l'accès. WEAppCheckingAccessResult checkResult = \_CheckPageAccess (pageAccess); // Récupérer à nouveau l'accès - Récupération 2. pageAccess = GetAccess (); // 1. Accès réfusé. Essayer de résoudre l'autorisation. if (checkResult != WEAppCheckingAccessResult.AUTHORIZED\_ACCESS && !\_TryChangePageAccess (pageAccess, checkResult)) { // Récupérer à nouveau l'accès - Récupération 3. pageAccess = GetAccess (); // Exécution du code de l'autorisation. \_PageAccessDenied (pageAccess, checkResult); // Générer une exception. throw new BSCInvalidOperationException ("Method \_PageAccessDenied must throws exception or aborts current thread"); } // Récupérer à nouveau l'accès - Récupération 4. pageAccess = GetAccess (); // Vérifier que l'accès est fourni. if (pageAccess == null) throw new BSCInvalidOperationException ("Null access"); // 2. Accès autorisé. if (pageAccess.AccessWeight > -1) pageAccess.AccessWeight --; // Status de l'accès de la page. pageAccess.PageAccessState = WEAppPageAccess.GetPageAccessState (); this.PageAccessState = pageAccess.PageAccessState; // Remplir la méthode de nettoyage d'accès si elle n'est pas renseignée. if (pageAccess.PageAccessClean == null) pageAccess.PageAccessClean = new WEAppPageAccessClean (PageAccessClean); // Imposer la culture francaise au Thread en cours. Thread.CurrentThread.CurrentCulture = this.AppCultureInfo;
-
hi, this is the code of my load :
protected override void OnLoad (EventArgs e)
{
try
{
// Ne pas inclure la page dans le cache client (Par défaut).
_ApplyCacheStrategy ();
// Titre.
string pageTitle = this.PageTitle;if (pageTitle != null && ( this.Title == null || this.Title == this.SessionData.PageTitleToOverride)) { this.Title = pageTitle; } // Inclure le script pour la vérification des erreurs coté serveur. \_AddCheckServerErrorScript (); // Inclure le script pour la gestion des erreurs coté client. \_AddJsReportingScript (); // Avoir le jeton de l'application racine. if (this.RootToken == null) this.RootToken = \_GetRootToken (); // Fixer la tâche en cours. this.\_PageTask = new WEAppPageTask (this.PageTaskString); // Vérifier l'accès à la page. WEAppPageAccess pageAccess; // Récupérer en cours de la page - Récupération 1. pageAccess = GetAccess (); // Vérifier l'accès. WEAppCheckingAccessResult checkResult = \_CheckPageAccess (pageAccess); // Récupérer à nouveau l'accès - Récupération 2. pageAccess = GetAccess (); // 1. Accès réfusé. Essayer de résoudre l'autorisation. if (checkResult != WEAppCheckingAccessResult.AUTHORIZED\_ACCESS && !\_TryChangePageAccess (pageAccess, checkResult)) { // Récupérer à nouveau l'accès - Récupération 3. pageAccess = GetAccess (); // Exécution du code de l'autorisation. \_PageAccessDenied (pageAccess, checkResult); // Générer une exception. throw new BSCInvalidOperationException ("Method \_PageAccessDenied must throws exception or aborts current thread"); } // Récupérer à nouveau l'accès - Récupération 4. pageAccess = GetAccess (); // Vérifier que l'accès est fourni. if (pageAccess == null) throw new BSCInvalidOperationException ("Null access"); // 2. Accès autorisé. if (pageAccess.AccessWeight > -1) pageAccess.AccessWeight --; // Status de l'accès de la page. pageAccess.PageAccessState = WEAppPageAccess.GetPageAccessState (); this.PageAccessState = pageAccess.PageAccessState; // Remplir la méthode de nettoyage d'accès si elle n'est pas renseignée. if (pageAccess.PageAccessClean == null) pageAccess.PageAccessClean = new WEAppPageAccessClean (PageAccessClean); // Imposer la culture francaise au Thread en cours. Thread.CurrentThread.CurrentCulture = this.AppCultureInfo;
That code doesn't set your _Session variable...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together. Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
-
Hi, I create a class library for my application that contains (_Session). Tha init method is very good built not have matter.It is seems in xmltextwriter exception
-
Hi guys, I have the above exception that appears to me when executing my code:
protected void Page_Load (object sender, EventArgs e)
{
//Génération du fichier XML.
if (this.Request ["ActionButton"] == "Generate")
{
string Json = "";
// Initiation de la collection
SLSalariesCollection salaries = new SLSalariesCollection (this._Session);
salaries.Init ();
// Création du fichier xml.
string fileName = @"D:\New Folder\MyXmlff.xml";
// Si le fichier existe effacer,
if (System.IO.File.Exists (fileName))
{
System.IO.File.Delete (fileName);
}
XmlTextWriter myXmlTextWriter = new XmlTextWriter ("D:/New Folder/MyXmlff.xml",System.Text.Encoding.UTF8);
myXmlTextWriter.Formatting = Formatting.Indented;
myXmlTextWriter.WriteStartDocument(false);
myXmlTextWriter.WriteStartElement("root");
myXmlTextWriter.WriteAttributeString("xmlns","urn:iso:std:iso:20022:tech:xsd:pain.001.001.02");
myXmlTextWriter.WriteStartElement("pain.001.001.02");
int j = 0;
// Récupérer la date d'Aujourd'huit de virement.
DateTime Now = DateTime.UtcNow;
string datevir = Now.ToString();
// Attribut Batch booking
Boolean batch = true;
//formatter la collection de salariés.
foreach (SLSalarie salari in salaries)
{
j++;
Json = Json + "{succeed : 1}";
myXmlTextWriter.WriteStartElement("Salarié", salari.Matricule);} myXmlTextWriter.Flush(); myXmlTextWriter.WriteEndElement(); myXmlTextWriter.WriteEndElement(); myXmlTextWriter.Close(); this.Response.ClearContent(); this.Response.Write(Json); this.Response.End(); }
the problem that the code is sometimes excuting very well,sometimes no and appear to me this fatal EXCEPTION. I think that it is problem of refreshing my references.i did this.The first time, ok running very well,the second time EXCEPTION appears. when doing breakpoints,the problem appears in the collection'initiation.How can I solve that? also when reading about the class xmltextwriter,i know that i should treat that in my code c#.So do i should to add to my code to solve that? Thank u very much for u help hugs
-
Hi guys, I have the above exception that appears to me when executing my code:
protected void Page_Load (object sender, EventArgs e)
{
//Génération du fichier XML.
if (this.Request ["ActionButton"] == "Generate")
{
string Json = "";
// Initiation de la collection
SLSalariesCollection salaries = new SLSalariesCollection (this._Session);
salaries.Init ();
// Création du fichier xml.
string fileName = @"D:\New Folder\MyXmlff.xml";
// Si le fichier existe effacer,
if (System.IO.File.Exists (fileName))
{
System.IO.File.Delete (fileName);
}
XmlTextWriter myXmlTextWriter = new XmlTextWriter ("D:/New Folder/MyXmlff.xml",System.Text.Encoding.UTF8);
myXmlTextWriter.Formatting = Formatting.Indented;
myXmlTextWriter.WriteStartDocument(false);
myXmlTextWriter.WriteStartElement("root");
myXmlTextWriter.WriteAttributeString("xmlns","urn:iso:std:iso:20022:tech:xsd:pain.001.001.02");
myXmlTextWriter.WriteStartElement("pain.001.001.02");
int j = 0;
// Récupérer la date d'Aujourd'huit de virement.
DateTime Now = DateTime.UtcNow;
string datevir = Now.ToString();
// Attribut Batch booking
Boolean batch = true;
//formatter la collection de salariés.
foreach (SLSalarie salari in salaries)
{
j++;
Json = Json + "{succeed : 1}";
myXmlTextWriter.WriteStartElement("Salarié", salari.Matricule);} myXmlTextWriter.Flush(); myXmlTextWriter.WriteEndElement(); myXmlTextWriter.WriteEndElement(); myXmlTextWriter.Close(); this.Response.ClearContent(); this.Response.Write(Json); this.Response.End(); }
the problem that the code is sometimes excuting very well,sometimes no and appear to me this fatal EXCEPTION. I think that it is problem of refreshing my references.i did this.The first time, ok running very well,the second time EXCEPTION appears. when doing breakpoints,the problem appears in the collection'initiation.How can I solve that? also when reading about the class xmltextwriter,i know that i should treat that in my code c#.So do i should to add to my code to solve that? Thank u very much for u help hugs
-
Hi guys, I have the above exception that appears to me when executing my code:
protected void Page_Load (object sender, EventArgs e)
{
//Génération du fichier XML.
if (this.Request ["ActionButton"] == "Generate")
{
string Json = "";
// Initiation de la collection
SLSalariesCollection salaries = new SLSalariesCollection (this._Session);
salaries.Init ();
// Création du fichier xml.
string fileName = @"D:\New Folder\MyXmlff.xml";
// Si le fichier existe effacer,
if (System.IO.File.Exists (fileName))
{
System.IO.File.Delete (fileName);
}
XmlTextWriter myXmlTextWriter = new XmlTextWriter ("D:/New Folder/MyXmlff.xml",System.Text.Encoding.UTF8);
myXmlTextWriter.Formatting = Formatting.Indented;
myXmlTextWriter.WriteStartDocument(false);
myXmlTextWriter.WriteStartElement("root");
myXmlTextWriter.WriteAttributeString("xmlns","urn:iso:std:iso:20022:tech:xsd:pain.001.001.02");
myXmlTextWriter.WriteStartElement("pain.001.001.02");
int j = 0;
// Récupérer la date d'Aujourd'huit de virement.
DateTime Now = DateTime.UtcNow;
string datevir = Now.ToString();
// Attribut Batch booking
Boolean batch = true;
//formatter la collection de salariés.
foreach (SLSalarie salari in salaries)
{
j++;
Json = Json + "{succeed : 1}";
myXmlTextWriter.WriteStartElement("Salarié", salari.Matricule);} myXmlTextWriter.Flush(); myXmlTextWriter.WriteEndElement(); myXmlTextWriter.WriteEndElement(); myXmlTextWriter.Close(); this.Response.ClearContent(); this.Response.Write(Json); this.Response.End(); }
the problem that the code is sometimes excuting very well,sometimes no and appear to me this fatal EXCEPTION. I think that it is problem of refreshing my references.i did this.The first time, ok running very well,the second time EXCEPTION appears. when doing breakpoints,the problem appears in the collection'initiation.How can I solve that? also when reading about the class xmltextwriter,i know that i should treat that in my code c#.So do i should to add to my code to solve that? Thank u very much for u help hugs
With: [ when doing breakpoints,the problem appears in the collection'initiation.How can I solve that? ] I think you meen this part of you code: [ // Initiation de la collection SLSalariesCollectio salaries = new SLSalariesCollection (this._Session); salaries.Init (); ] Did you check the value of 'this._Session' before initializing your collection?