The importance of calling .Close()

Courtesy of Andrew Westgarth, via IM, I found myself look at Visual Basic code last week. Andrew’s “designer” was having problems editing some files that made up an application that Andrew was developing…seemed that something was keeping a lock on the files such that they couldn’t be edited. I suggested a couple of things, including hard-coding the filename (avoiding use of Server.MapPath) just to see what happened.

However, after a little experimentation, it turns out that the XmlReader instance wasn’t being closed and as such was keeping a lock on the XSL/T file in question. The solution was to call the .Close() method. It’s obvious now, however sometimes whilst in thick of it, it’s very easy forget to call such methods, nobody’s perfect.

Andrew provides a full write-up over here:

***warning contains VisualBasic code***
Can’t Save your XSL/T File? Have You Closed Your XMLReader?/a>

Technorati Tags: , , , ,