2

The application in question is written in C#. We are late in the development cycle, close to launch on our application. One of my coworkers is seeing the following issue:

When he logs out of his Windows 7 session while the application is running, he gets a "csc.exe - Application Error" popup window that says "The application was unable to start correctly (0xc0000142). Click OK to close the application."

I believe that I have tracked this down to the fact that we update the application's XML config file on exit, and the code uses XmlSerializer. According to this question, XmlSerializer launches csc.exe to compile serialization assemblies dynamically on an as-needed basis, at run time. My suspicion is bolstered by the fact that, if I remove the update to the config file at exit time, then my coworker no longer sees the error message in question.

Can someone explain to me in more detail what is happening here? Why does csc.exe fail to start properly when executed at system logout? Is there some low-risk solution that I can put in place to mitigate the problem?

Things I have considered:

  • Use sgen to generate the serialization assemblies and deploy them with the application. This sounds promising, but my experiments with it were pretty dismal. It seems to only be able to generate a DLL either for an entire assembly or for a single class, no way to specify a list of classes. Also, when I point it to one of my assemblies, it starts complaining about classes in the assembly with duplicate names.
  • Use another means to read / write the XML. I'm not confident about implementing this at our current stage of development. We are hoping to launch soon, and this feels like too much of a risk.
Community
  • 1
  • 1
danBhentschel
  • 863
  • 7
  • 24
  • In general processes are not allowed to start when system is getting shut down. I recommend saving changes to config file as soon as configuration actually changes. – Tar Oct 08 '14 at 12:37
  • Perhaps `DataContractSerializer` would be feasible? – BartoszKP Oct 08 '14 at 12:37
  • Thanks, @Tar. I appreciate the suggestion. While user settings and preferences are saved at the time the change is made, there are other things such as window placement, open views, etc. that are in that config file that I don't think should be saved on an ongoing basis. I suppose I could have some kind of timer fire periodically to make updates to the file if necessary, but this feels messy, and I think is too complex and fragile to implement just before launch, as well as it would still be susceptible to the shutdown error we have today, depending on timing. – danBhentschel Oct 08 '14 at 12:53
  • 1
    I appreciate the suggestion, @BartoszKP. I had dismissed this as "another way to read / write XML", but since you took the time to suggest it, I decided to look into it a bit more. At a first glance, the usage looks similar enough to XmlSerializer that I might be able to substitute it with minimal risk. I will have to do some experimentation. Thankfully, the XML parser has unit tests already, so that should make my job much easier. – danBhentschel Oct 08 '14 at 12:58
  • It is a difficult error to troubleshoot, especially so when it only occurs at shutdown. I'd ignore it, too unusual. If you want a quick fix anyway then use the notification you get and call Environment.Exit(). – Hans Passant Oct 08 '14 at 14:31
  • Thanks again to @BartoszKP. I have played around with DataContractSerializer enough to determine that it is not a solution to the problem at this time. Unfortunately, it stores the data in a fundamentally different looking XML document than XmlSerializer does, and switching has highlighted some places in the application where we parse the XML with a reader, expecting it to follow a certain pattern. This whole investigation has exposed several ways we should do things differently, but again, now is not the time for such changes. – danBhentschel Oct 08 '14 at 14:36
  • @danBhentschel I understand. No other idea unfortunately - good luck! – BartoszKP Oct 08 '14 at 14:41
  • Late to the party, with a question. `XmlSerializer` launches `csc.exe` in its constructor. Could you generate an `XmlSerializer` for yourself when your application launches, save it in some static, and use it later on shutdown? – dbc Oct 26 '14 at 21:51

0 Answers0