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. General Programming
  3. .NET (Core and Framework)
  4. Strangest bug I think I've seen

Strangest bug I think I've seen

Scheduled Pinned Locked Moved .NET (Core and Framework)
helpcsharpcssvisual-studioxml
2 Posts 2 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.
  • D Offline
    D Offline
    darrellp
    wrote on last edited by
    #1

    This is probably one of the strangest things I think I've seen while working in .NET and I have yet to figure out even a workaround, much less why it might be occurring. I've got a very strange bug happening which I was finally able to distill down to a problem with writing to ..\..\app.config after a file open dialog. It appears that if a standard file open dialog is closed with the "open" button then any future writes to app.config just magically disappear into the bit bucket (am I the only one still using that term?). No errors, no exceptions thrown. In fact, if you close the app.config stream and open it from scratch, the changes just written appear to be there but when the app finishes, they aren't there. This sounds like a buffering problem but I'm setting the stream to autoflush and flushing/closing it after the save. Also, if you have the file open in the IDE at the time, you can write to it and save it just fine. None of this happens when you hit the cancel key in the open file dialog even though I'm totally ignoring the return from the dialog in both cases. None of it happens with files other than ..\..\app.config (at least not with the sample file I tried in my temp directory). :confused::confused::confused::confused: I have no idea why the file open dialog and app.config would be tied together in such an inextricable manner. I don't know how I'd simulate such a strange situation WRT app.config even if I tried. The best I can think of is to overwrite app.config and change it's creation date back to what it was originally but this isn't happening because I can write to it from the IDE while this is happening and those writes aren't overwritten. This one definitey has me scratching my head. To illustrate the bug I wrote a tiny app with a single button which calls the following function when the button is pressed. This pretty much illustrates everything I'm talking about (forgive the formatting - all my blank lines seem to drop out in the <pre> block - anybody know how to get them to show up?):

    private void XMLBugSave()
    {
    // Everything works fine if you use a file other than ..\..\app.config...

    // const string strFile = @"d:\\temp\\testbug.xml"; 
    const string strFile = @"..\\..\\app.config"; 
    
    XmlTextReader xr = new XmlTextReader(strFile); 
    xdoc = new XmlDocument(); 
    xdoc.Load(xr); 
    xr.Close(); 
    
    Random rnd = new Random(); 
    string strNodeName = "NODE\_" + rnd.Next().ToString(); 
    Console.WriteLine("Attempting to add Element " +
    
    A 1 Reply Last reply
    0
    • D darrellp

      This is probably one of the strangest things I think I've seen while working in .NET and I have yet to figure out even a workaround, much less why it might be occurring. I've got a very strange bug happening which I was finally able to distill down to a problem with writing to ..\..\app.config after a file open dialog. It appears that if a standard file open dialog is closed with the "open" button then any future writes to app.config just magically disappear into the bit bucket (am I the only one still using that term?). No errors, no exceptions thrown. In fact, if you close the app.config stream and open it from scratch, the changes just written appear to be there but when the app finishes, they aren't there. This sounds like a buffering problem but I'm setting the stream to autoflush and flushing/closing it after the save. Also, if you have the file open in the IDE at the time, you can write to it and save it just fine. None of this happens when you hit the cancel key in the open file dialog even though I'm totally ignoring the return from the dialog in both cases. None of it happens with files other than ..\..\app.config (at least not with the sample file I tried in my temp directory). :confused::confused::confused::confused: I have no idea why the file open dialog and app.config would be tied together in such an inextricable manner. I don't know how I'd simulate such a strange situation WRT app.config even if I tried. The best I can think of is to overwrite app.config and change it's creation date back to what it was originally but this isn't happening because I can write to it from the IDE while this is happening and those writes aren't overwritten. This one definitey has me scratching my head. To illustrate the bug I wrote a tiny app with a single button which calls the following function when the button is pressed. This pretty much illustrates everything I'm talking about (forgive the formatting - all my blank lines seem to drop out in the <pre> block - anybody know how to get them to show up?):

      private void XMLBugSave()
      {
      // Everything works fine if you use a file other than ..\..\app.config...

      // const string strFile = @"d:\\temp\\testbug.xml"; 
      const string strFile = @"..\\..\\app.config"; 
      
      XmlTextReader xr = new XmlTextReader(strFile); 
      xdoc = new XmlDocument(); 
      xdoc.Load(xr); 
      xr.Close(); 
      
      Random rnd = new Random(); 
      string strNodeName = "NODE\_" + rnd.Next().ToString(); 
      Console.WriteLine("Attempting to add Element " +
      
      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      you'll kick yourself when you read this. .NET Framework Class Library OpenFileDialog.OpenFile Method http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsopenfiledialogclasstopic.asp

      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