#Google Analytic Tracker

Pages

Apr 8, 2008

Process cannot access the file! Please close your XmlReader!

At work, we have many scripts and utility programs to aid us in testing and developing our product.

After upgraded to VS 2008, I notice that one of utilities that I run regularly no longer working.

Here is the error that I got:

The process cannot access the file 'c:\xxx\yyy.xml' because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, Fil
eOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.Xml.XmlDocument.Save(String filename)
   at GenRes.GenRes.Main(String[] args) in C:\xxx\GenRes.cs:line 191

I asked all my colleges, and they don't have any problem running this utility.

Struggling with the fact why my computer doesn't run the utility properly, I start debugging line by line in VS.

Looking into the GenRes.cs file, it is what it tries to do.

// Load Data to XmlDocument
XmlDocument xmlStringsdoc = new XmlDocument();
xmlStringsdoc.Load(XmlReader.Create(args[0] + ".xml", settings));
//...
// Save Data back to the xml file
xmlStringsdoc.Save(args[0] + ".xml");

Strangely, when I run the utility in the debugger, I don't get any error.

Not really sure why (which I hope I eventually find out), I decided to see if I can fix the code so that it will work on my machine, and hopefully it will works on others too.

By analyzing the code, most likely I get this error because XmlReader isn't close when xmlStringdoc try to save the data.

Looking into the revision of the file. I notice that one of my college changed the following:

//FROM xmlStringsdoc.Load(args[0] + ".xml"); // TO
settings = new XmlReaderSettings();
settings.ProhibitDtd = false;
xmlStringsdoc.Load(XmlReader.Create(args[0] + ".xml", settings));

It turns out that we don't want to prohibit DTD when process the file.

Here is the simple fix

   1: XmlReader l_oXmlReader = XmlReader.Create(args[0] + ".xml", settings);
   2: xmlStringsdoc.Load(l_oXmlReader);
   3: // Close the reader since it is no longer needed
   4: l_oXmlReader.Close(); 

All I have done is CLOSE the reader! After testing the code, it works.

Here is the reminding questions I want to know:

  1. Does XmlDocument.Load(string) automatically close the file?
  2. Why this issue only happen on my machine and not others, is there some kind of  windows or .net framework setting?
  3. How can you write a unit test to ensure this utility work on all developers machine?
  4. How come I don't get an error when running the code in Debugger?
  5. Why does the error message say the file is being used by another process (but in fact, it is the same process that accessing it)?

Hopefully I can answer this question in the future.

Mar 16, 2008

Visual Studio Installation Strange Disk Space Requirement

Recently I attended "Hero Happen Here" event in Calgary, and obtained a copy of Visual Studio 2008 Standard Edition.  Similar to the Visual Studio 2005 lunch event, everyone get a copy of Visual Studio Standard edition. But since this is my first time attending such event, I was pretty excited that I got my own Visual Studio 2008.

After I got back home, I immediately uninstall my Visual Studio 2008 beta version.

Surprisingly, the first error that I encountered is not during VS installation (although I usually have faith that VS will install properly), but rather when I uninstall the beta.

"no disk Exception Processing Message c0000013 Parameters ...."

By doing a quick google search, I found this forum.  I recalled that I installed the beta from a external hard drive. I must have removed the VS 2008 installation file or changed the drive letter. My quick fix was to unplug my external hard drive, and uninstall the beta. But really, a software shouldn't need to check for disk during un-installation.

Anyhow, here is what strange about my VS 2008 installation experience. Notice my installation path is on C drive, but the Disk space requirements show that I need 204 MB on my E drive.

Strange VS Installation with Hightlight

My E drive only stores my media files like music. I never use this drive for program installation of virtual memory mapping.

After I installation, I checked my E drive and it doesn't seem to have any extra file installed. It would make more sense if it is D drive because this is where I store my user profile!

Mar 11, 2008

My First Experience with xUbuntu

Awhile ago, I promised my sister I would format her laptop. Her laptop, a SONY VAIO FX340 (800Mhz), has a broken LAN port and a broken memory slot. Her laptop can only run on 256 MB RAM max and has connect to Internet though D-Link 650 Express card.

Minimum Requirements

Initially, I downloaded Ubuntu and tried to install it.  However, every time I select the "Start and Install Ubuntu" or the "VGA Mode" in the boot up screen, I only got a blank screen. After doing some researches,  it turns out that Ubuntu needs a minimum of 387 MB.  I stumbled upon a forum about xUbuntu. It turns out that there are number of "spin-off" projects that based on Ubuntu.

xUbuntu uses a different desktop environment call Xfce. I am guessing this interface require less memory, because its minimum requirement is 128 MB.

Download

Download Ubuntu is easy and extreme fast. Using P2P Bit Torrent, I got up to 600kB/sec from my cable Internet. Man, I never see this kind of speed before using cable internet. I am so glad I switch from ADSL to cable! There are many peers and seeds out there so you won't have issue downloading it.

Installation

First, I used to start up xUbuntu using the first boot option. Well, it didn't work, it definitely related to the video card.  So I start up xUbuntu using VGA mode. After 10 minutes of loading... it loaded! a very small 640 x480 screen shows up.

The reason why it takes awhile to load is because it loads the core system to your RAM only. This mean you can literally run Ubuntu from a CD ROM without effecting your Windows XP system. This is an EXCELLENT idea, because it allows me to test and experience Ubuntu before I decided to install it onto the harddrive!

i.e. if you can't run Ubuntu just from Live CD, you may have trouble installing it. You are better to do more research before installing it.

However, it was impossible to run the installation with 640 x 480 screen. The installation dialogue box was much larger (no resize available) than the screen resolution. After some clicking around, I find that going though Applications->Settings->Screens and Graphics allows me to change the video card. Fortunately, xUbuntu comes with a number of video drive. The laptop uses Intel 815, which I quickly find it. After changed the video and resolution. xUbuntu requests me to logout so that changes can take effect.

Ah ha! Here was the problem. After I logout to the main screen, I have no idea how to log back in because I don't know the default user. I tried login as root and xUbuntu disallow me to log on using Xfce Session. The ultimate solution is to restart the machine. However, my video card setting didn't get persisted after restart.

To work around this issue, I created another user.  Luckily 80% of the Create User dialogue box fit on the screen.  After I changed the video setting, log out, and log back on, everything works accordingly. Btw, I did figured out that the default user is "ubuntu" by random guesses.

Installation is very easy, only 7 steps!  There was no interruption, other than it complained it can't get the latest security update because it had no Internet connection.

Also, my D-Link 640 was automatically detected and ready to use. It seamlessly installed the driver for it.

Desktop Screenshot

In the screenshot, GIMP is a very featured graphical editor. It supports layering and many effects you can use, and it is FREE!

Add/Remove Application

xUbuntu comes with this nice application call "Add/Remove Application", similar to Windows Add/Remove.

I opened it up, and the first trouble I had with xUbuntu was downloading new applications, even though it showed me a list of available application.  My problem is exactly mentioned here:

http://ubuntuforums.org/showthread.php?t=629621

Thanks to the strong community, it was that hard to find the solution.

Unlike like MS Windows, where you have to go online and click download for new software, the Linux community has setup a free applications repository for download. You can easy browse all available software and install the one that you selected.

I was surprised the number of freebie you can download. It even comes with the popularity rating.

Add Remove Application Screenshot

The Terminal

The one last problem that I needed to resolve was a crashing Terminal. Here is the problem and solution:

http://ubuntuforums.org/showthread.php?t=417661

I was surprised Linux would have a problem when opening a terminal. Terminal in Linux is essential for administrative works.

Notice that since my terminal doesn't work, I have to logon to Failsafe Terminal Session in the logon screen so that I can edit the configuration file using my all time favour editor, pico.

Menu Screenshot

Reasons why you want to use Ubuntu

A. You got tire of Windows XP (note that I didn't say XP is bad or worst than Linux, XP has many advantages too).

B. You need an OS that run fast though highly customization on a relatively slow machine.

C. You want to startup a business with low budget that still uses legitimate software. (you SHOULD use legitimate software) You can download a lot of free Linux software!

Is Ubuntu Ready for the Average Joe?

Well, I say Ubuntu is getting there, but not quiet yet. From the Desktop user interface perspective, it is definitely ready. Anyone who has experience with Windows XP should have much problem using Ubuntu. 

However, there is some fundamental ideas that the average XP desktop user need understand.

1. It is the idea of security, the different between root user and standard user.

2. User will need be comfortable editing configuration files.  There still a lot of configuration issue that can only be solved without a friendly Graphical User Interface (GUI).

3. The file system. The idea of mount to a physical storage, instead of the Window drivers from A to Z.

File Manager

Note there is no C, D, or E drive in the screenshot. Only directories or folders.

Linux Desktop environment has get to the point where you barely need to do command line. Thanks to the Linux community and the open source projects.  A lot more average joes can use Linux OS.

Nevertheless, MS Windows will still be dominated OS.  MS had spend a lot of money and marketing to get software company to write drivers for it, and ensure that its OS works in almost every PC.  This is what consumer pay for, it is the services and consistent support of the software. That is also one of the ways for open-source developers to earn money, it is the services and business solutions they provide.