Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Mysterious null value bug

Mysterious null value bug

Scheduled Pinned Locked Moved The Lounge
csharpcomdata-structuresxmlhelp
14 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RickZeeland
    wrote on last edited by
    #1

    Suddenly several people are reporting problems with the XML .config file of our application, it is filled with null values only. It seems to be related to PC resets or power loss, see: c# - What could cause an XML file to be filled with null characters? - Stack Overflow[^] Anyone else ever encountered this?

    P D J 3 Replies Last reply
    0
    • R RickZeeland

      Suddenly several people are reporting problems with the XML .config file of our application, it is filled with null values only. It seems to be related to PC resets or power loss, see: c# - What could cause an XML file to be filled with null characters? - Stack Overflow[^] Anyone else ever encountered this?

      P Offline
      P Offline
      Phil J Pearson
      wrote on last edited by
      #2

      Yes, I encountered it numerous times on numerous different machines, despite them all having a UPS to ensure a clean shutdown on power failure. I created a ConfigurationUncorrupter class. It detects when an app startup is complete and configuration has been successfully loaded then it creates a safe copy of the config file. If, on the other hand, loading configuration fails, it replaces the config file with the backup from the last successful start and tries again. Every app gets that class incuded. That has pretty much eliminated the problem for me.

      Phil


      The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

      D J 2 Replies Last reply
      0
      • P Phil J Pearson

        Yes, I encountered it numerous times on numerous different machines, despite them all having a UPS to ensure a clean shutdown on power failure. I created a ConfigurationUncorrupter class. It detects when an app startup is complete and configuration has been successfully loaded then it creates a safe copy of the config file. If, on the other hand, loading configuration fails, it replaces the config file with the backup from the last successful start and tries again. Every app gets that class incuded. That has pretty much eliminated the problem for me.

        Phil


        The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

        D Offline
        D Offline
        dandy72
        wrote on last edited by
        #3

        I like that idea a lot, as part of a belt-and-suspenders system. But this begs the question, I'd be very curious to know what happens so frequently and in such a repeatable fashion that such a thing had to be written in response to this recurring situation. I mean, a config file is typically something that should be read (in read-only mode) at startup and then closed and left alone. Then even if the system isn't shut down cleanly, that config file should be safe. The only time it should be at risk is when it's opened to write new data into it or edit existing data. What gets it corrupted so easily? And I hope that when your Uncorrupter class knows it has to intervene and restore the config file from a backup, it logs everything it possibly can to try to narrow down any potential source. Because that's not a "normal" state of operation. I'd be very uncomfortable knowing this auto-restore code gets triggered on a regular basis without understanding why.

        P 1 Reply Last reply
        0
        • P Phil J Pearson

          Yes, I encountered it numerous times on numerous different machines, despite them all having a UPS to ensure a clean shutdown on power failure. I created a ConfigurationUncorrupter class. It detects when an app startup is complete and configuration has been successfully loaded then it creates a safe copy of the config file. If, on the other hand, loading configuration fails, it replaces the config file with the backup from the last successful start and tries again. Every app gets that class incuded. That has pretty much eliminated the problem for me.

          Phil


          The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

          J Offline
          J Offline
          Jorgen Andersson
          wrote on last edited by
          #4

          Article?

          Wrong is evil and must be defeated. - Jeff Ello

          OriginalGriffO 1 Reply Last reply
          0
          • J Jorgen Andersson

            Article?

            Wrong is evil and must be defeated. - Jeff Ello

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #5

            Verb?

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            P 1 Reply Last reply
            0
            • OriginalGriffO OriginalGriff

              Verb?

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              Expletive!

              Mircea NeacsuM 1 Reply Last reply
              0
              • P PIEBALDconsult

                Expletive!

                Mircea NeacsuM Offline
                Mircea NeacsuM Offline
                Mircea Neacsu
                wrote on last edited by
                #7

                This thread is almost like CCC: The - article s**t - expletive happens - verb :laugh:

                Mircea

                1 Reply Last reply
                0
                • R RickZeeland

                  Suddenly several people are reporting problems with the XML .config file of our application, it is filled with null values only. It seems to be related to PC resets or power loss, see: c# - What could cause an XML file to be filled with null characters? - Stack Overflow[^] Anyone else ever encountered this?

                  D Offline
                  D Offline
                  DerekT P
                  wrote on last edited by
                  #8

                  Part of me is thinking this is a wind-up, right? I mean; power goes off, computer dies; and with the last few spare electrons the dedicated "XML File Writer" chip is enabled and the special write-only head on the slowing diskdrive momentarily lights up to zap the file to all zeros. Or wait, does it convert them to spaces? Or re-write the entire file removing the data between the XML tags? But surely it also needs to adjust the sectors after the end-of-file, or maybe even move the file elsewhere, which means updating the FAT, which means knowing where it is... Man, that chip has some pretty intense logic hard-wired into it. But seriously; a power failure causing a specific type of file to have a specific type of corruption written to it? However, having read that SO issue, it does begin to sound like there is some logic to it. All I can say is that in 25 years of using Windows, with a fair number of power failures and OpSys crashes along the way, I'm not aware of such a situation arising, ever. That's not to say it hasn't; maybe the software has corrected itself or maybe I've never needed to access affected files. That XML configuration files are frequently the victims, though, suggests to me that there is something in the CLR that is inappropriately readying the XML file for a write FAR too soon. This smacks of just really poor design within the MS subsystem, or an actual bug. This doesn't surprise me. Thank for highlighting it here!

                  R 1 Reply Last reply
                  0
                  • D DerekT P

                    Part of me is thinking this is a wind-up, right? I mean; power goes off, computer dies; and with the last few spare electrons the dedicated "XML File Writer" chip is enabled and the special write-only head on the slowing diskdrive momentarily lights up to zap the file to all zeros. Or wait, does it convert them to spaces? Or re-write the entire file removing the data between the XML tags? But surely it also needs to adjust the sectors after the end-of-file, or maybe even move the file elsewhere, which means updating the FAT, which means knowing where it is... Man, that chip has some pretty intense logic hard-wired into it. But seriously; a power failure causing a specific type of file to have a specific type of corruption written to it? However, having read that SO issue, it does begin to sound like there is some logic to it. All I can say is that in 25 years of using Windows, with a fair number of power failures and OpSys crashes along the way, I'm not aware of such a situation arising, ever. That's not to say it hasn't; maybe the software has corrected itself or maybe I've never needed to access affected files. That XML configuration files are frequently the victims, though, suggests to me that there is something in the CLR that is inappropriately readying the XML file for a write FAR too soon. This smacks of just really poor design within the MS subsystem, or an actual bug. This doesn't surprise me. Thank for highlighting it here!

                    R Offline
                    R Offline
                    RickZeeland
                    wrote on last edited by
                    #9

                    It might also have to do with the complicated way the settings are written by several applications to the same config file. We use Mutexes to prevent applications accessing this file at the same time. In the past the applications just wrote to their own config file, but it was decided that everything should be written to the same file ... :~

                    P 1 Reply Last reply
                    0
                    • R RickZeeland

                      Suddenly several people are reporting problems with the XML .config file of our application, it is filled with null values only. It seems to be related to PC resets or power loss, see: c# - What could cause an XML file to be filled with null characters? - Stack Overflow[^] Anyone else ever encountered this?

                      J Offline
                      J Offline
                      Joe Woodbury
                      wrote on last edited by
                      #10

                      Years ago, I ran into something similar with compiles. I eventually tracked it down to "endpoint" software which would "see" a change and try to back up files that would stop them from being written correctly.

                      1 Reply Last reply
                      0
                      • D dandy72

                        I like that idea a lot, as part of a belt-and-suspenders system. But this begs the question, I'd be very curious to know what happens so frequently and in such a repeatable fashion that such a thing had to be written in response to this recurring situation. I mean, a config file is typically something that should be read (in read-only mode) at startup and then closed and left alone. Then even if the system isn't shut down cleanly, that config file should be safe. The only time it should be at risk is when it's opened to write new data into it or edit existing data. What gets it corrupted so easily? And I hope that when your Uncorrupter class knows it has to intervene and restore the config file from a backup, it logs everything it possibly can to try to narrow down any potential source. Because that's not a "normal" state of operation. I'd be very uncomfortable knowing this auto-restore code gets triggered on a regular basis without understanding why.

                        P Offline
                        P Offline
                        Phil J Pearson
                        wrote on last edited by
                        #11

                        Yes, it does all the appropriate logging. The problem only occurs on startup and I'm sure it's not caused by any of my code. My code never explicitly writes to the config file. I have a much more complex, multi-application, shared configuration system that doesn't suffer from the same problem. It's only the very simple, standard, AppName.exe.config file that is ever affected.

                        Phil


                        The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

                        D 1 Reply Last reply
                        0
                        • R RickZeeland

                          It might also have to do with the complicated way the settings are written by several applications to the same config file. We use Mutexes to prevent applications accessing this file at the same time. In the past the applications just wrote to their own config file, but it was decided that everything should be written to the same file ... :~

                          P Offline
                          P Offline
                          Phil J Pearson
                          wrote on last edited by
                          #12

                          See my reply to dandy72, above.

                          Phil


                          The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

                          1 Reply Last reply
                          0
                          • P Phil J Pearson

                            Yes, it does all the appropriate logging. The problem only occurs on startup and I'm sure it's not caused by any of my code. My code never explicitly writes to the config file. I have a much more complex, multi-application, shared configuration system that doesn't suffer from the same problem. It's only the very simple, standard, AppName.exe.config file that is ever affected.

                            Phil


                            The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

                            D Offline
                            D Offline
                            dandy72
                            wrote on last edited by
                            #13

                            Gotcha. I wasn't trying to blame your code, and the fact that others have reported the same problem doesn't surprise me. That pretty much rules yours out. So given those circumstances, I think you're doing exactly the right thing - it's out of your control, but you anticipate it and do the best to recover gracefully given the circumstances. And you log it so you know when it happens. So you should have all the ammunition you need when someone tries to place some blame.

                            P 1 Reply Last reply
                            0
                            • D dandy72

                              Gotcha. I wasn't trying to blame your code, and the fact that others have reported the same problem doesn't surprise me. That pretty much rules yours out. So given those circumstances, I think you're doing exactly the right thing - it's out of your control, but you anticipate it and do the best to recover gracefully given the circumstances. And you log it so you know when it happens. So you should have all the ammunition you need when someone tries to place some blame.

                              P Offline
                              P Offline
                              Phil J Pearson
                              wrote on last edited by
                              #14

                              Thanks. I didn't think you were blaming me; I just wanted to be clear for the sake of others encountering the same problem.

                              Phil


                              The opinions expressed in this post are not necessarily those of the author, especially if you find them impolite, inaccurate or inflammatory.

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups