Click here to Skip to main content
15,172,951 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Managing User Accounts and Gruops at Runtime Pin
Anonymous17-Sep-04 13:14
MemberAnonymous17-Sep-04 13:14 
GeneralUsing Windows XP Visual Styles Pin
aninddroy17-Sep-04 0:24
Memberaninddroy17-Sep-04 0:24 
QuestionHow does .net runtime bind an assembly at runtime Pin
pgupta808016-Sep-04 22:30
Memberpgupta808016-Sep-04 22:30 
AnswerRe: How does .net runtime bind an assembly at runtime Pin
sukesh.g19-Sep-04 21:42
Membersukesh.g19-Sep-04 21:42 
General.NET Remoting hosted in IIS Pin
be kunkun16-Sep-04 21:01
Memberbe kunkun16-Sep-04 21:01 
GeneralIrregular shaped forms Pin
loewe19876516-Sep-04 20:20
Memberloewe19876516-Sep-04 20:20 
GeneralAuthorization and Profile Application Blocks Pin
nkiran15-Sep-04 19:57
Membernkiran15-Sep-04 19:57 
GeneralStrangest bug I think I've seen Pin
darrellp15-Sep-04 6:52
Memberdarrellp15-Sep-04 6:52 
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: 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 " + strNodeName); 

    xdoc.DocumentElement.AppendChild(xdoc.CreateNode(XmlNodeType.Element, strNodeName, null)); 

    OpenFileDialog ofd = new OpenFileDialog(); 
    // If you click "Cancel" in the following Dialog, then everything with the XML file works as 
    // expected. If you click "Open" then everything will seem to work at runtime - even 
    // reopening the file and looking at the result "verifies" that the save worked but in 
    // reality, nothing is written to the file. Very odd. 
    ofd.ShowDialog(); 

    StreamWriter sw = new StreamWriter(strFile); 
    sw.AutoFlush = true; 
    xdoc.Save(sw); 
    sw.Flush(); 
    sw.Close(); 

    // If you go back to the IDE after pressing open with app.config already opened in 
    // an IDE window, then nothing appears to have changed. You can change app.config in the 
    // IDE and save it out and your saves will persist. 
    MessageBox.Show("Verify file..."); 

    xr = new XmlTextReader(strFile); 
    xdoc = new XmlDocument(); 
    xdoc.Load(xr); 
    xr.Close(); 

    XmlNode xn = xdoc.SelectSingleNode(@"/configuration/" + strNodeName); 

    // This always seems to verify whether or not the file was written. 
    Console.WriteLine(xn == null ? "unverified" : "verified"); 
} 

GeneralRe: Strangest bug I think I've seen Pin
Anonymous15-Sep-04 7:49
MemberAnonymous15-Sep-04 7:49 
GeneralApplication Protection Pin
Member 132035214-Sep-04 23:18
MemberMember 132035214-Sep-04 23:18 
GeneralActiveX problem Pin
archetype14-Sep-04 2:36
Memberarchetype14-Sep-04 2:36 
Generalcharts in visual c++ Pin
dana_krycek14-Sep-04 2:35
Memberdana_krycek14-Sep-04 2:35 
GeneralRe: charts in visual c++ Pin
ursus zeta15-Sep-04 14:51
Memberursus zeta15-Sep-04 14:51 
GeneralRe: charts in visual c++ Pin
dana_krycek16-Sep-04 9:24
Memberdana_krycek16-Sep-04 9:24 
GeneralSorry for not Replying Pin
ursus zeta22-Sep-04 12:51
Memberursus zeta22-Sep-04 12:51 
Generalhelp in list view control Pin
bora3ee13-Sep-04 10:51
Memberbora3ee13-Sep-04 10:51 
GeneralRe: help in list view control Pin
Tomas Petricek15-Sep-04 15:29
MemberTomas Petricek15-Sep-04 15:29 
Generalhelp in process class Pin
bora3ee13-Sep-04 10:49
Memberbora3ee13-Sep-04 10:49 
QuestionIs there a way to use a DataTable in COM ? Pin
DavPen13-Sep-04 9:27
MemberDavPen13-Sep-04 9:27 
GeneralImage filter for black and white images in GDI+ Pin
BLBANET13-Sep-04 5:07
MemberBLBANET13-Sep-04 5:07 
GeneralRe: Image filter for black and white images in GDI+ Pin
Anonymous15-Sep-04 8:25
MemberAnonymous15-Sep-04 8:25 
GeneralMultithreaded Design Question Pin
tulip1234512-Sep-04 1:01
Membertulip1234512-Sep-04 1:01 
QuestionHow to catch mouse click message? Pin
Volvere10-Sep-04 15:02
MemberVolvere10-Sep-04 15:02 
AnswerRe: How to catch mouse click message? Pin
Tomas Petricek11-Sep-04 15:34
MemberTomas Petricek11-Sep-04 15:34 
GeneralCustomizing the .Net framework Launch Condition Message Pin
kornstyle10-Sep-04 7:20
Memberkornstyle10-Sep-04 7:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.