I have an application that saves data as an XML file when the application exits. There is no problem with this process when the application exits. If the application is running when Windows XP is shut down, I receive the following error box:
csc.exe - Application Error
The applciation failed to initialize properly (0xc0000142). Click on OK to terminate the application.
What can I do to serialize out the data so I do not recieve this error
Thanks,
Russell Hunter
Here is a sample that shows the error:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Xml; using System.Xml.Serialization; namespace TestExit {public partial class Form1 : Form { public Form1() {
InitializeComponent();} private void Form1_FormClosing(object sender, FormClosingEventArgs e) {
XmlSerializer xs = null; XmlTextWriter xmlTw = null; try {
List<int> a = new List<int>(); xs = new XmlSerializer(a.GetType()); xmlTw = new XmlTextWriter("test.xml", System.Text.Encoding.UTF8); xmlTw.Formatting = Formatting.Indented; xs.Serialize(xmlTw, a); } finally {
if (xmlTw != null) xmlTw.Close(); } } } }

CSC error when serializing as Windows is shutting down
PierreE
Hi Russell,
This is not available in .NET 1.1. because it is the runtime behavior to load the compiled assembly.
Otherwise, even if we compile an assembly, the .NET runtime will not be active to load the assembly.
If you still have any concern, please feel free to post here.
Best regards,
Peter Huang
rlshearer
Hi Russell,
Because XML serialize code is generated dynamically, it will call the csc.exe to compile the dynamical assembly. But when the windows is going to shut down we should not create new process.
So far I think you may try to usethe Sgen tool to precompile the assembly.
XML Serializer Generator Tool (Sgen.exe)
http://msdn2.microsoft.com/en-us/library/bk3w6240.aspx
Introducing XML Serialization
http://msdn2.microsoft.com/en-us/library/182eeyhh.aspx
If you still have any concern, please feel free to post here.
Best regards,
Peter Huang
Craig Colomb
Thank you. This was very good to know.
Do you know if there is something like sgen for .Net 1.1
Russell Hunter