Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 209829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:57:02+00:00 2026-05-11T17:57:02+00:00

At work, we have migrated from Windows XP to Windows Vista. After the migration,

  • 0

At work, we have migrated from Windows XP to Windows Vista. After the migration, some of my unit tests, using nUnit, started to randomly fail with the System.UnauthorizedAccessException being thrown. The failing tests each involve writing files used for tests stored as embedded resources in the test DLL to the current directory, running the tests, then deleting them, typically in the setup/teardown or the fixture setup/teardown, in rapid succession. I do this so that my tests are agnostic to the location on each developer’s drive that they are ran from and not worrying about relative file paths.

While troubleshooting this, I found that it related to the creation and deletion of the files. On deletion, each delete follows the pattern:

if( File.Exists(path) ) { File.Delete(path) }

When I surround this with a try-catch block and breakpoint on the catch (if the exception was thrown), the file would already be deleted from the disk. For the failures of file creation, usually using XmlWriter or StreamWriter, each are specified to overwrite the file if it exists.

Odd thing is, while investigating, I created this C# program that seems to recreate the exception:

class Program
{
    static void Main(string[] args)
    {
        int i = 0;
        try
        {              
            while (true)
            {
                System.IO.TextWriter writer = new System.IO.StreamWriter("file.txt");
                i++;
                System.Console.Out.WriteLine(i);
                writer.Write(i);
                writer.Close();
                System.IO.File.Delete("file.txt");
            }
        }
        catch (System.UnauthorizedAccessException ex)
        {
            System.Console.Out.WriteLine("Boom at: " + i.ToString());
        }

    }
}

On one of our machines that still has XP on it, it will keep iterating into the hundreds of thousands without excepting until I kill it. On any of our Vista machines, it will print “Boom” anywhere between 150 and 500 iterations.

Since I do not have access to a Vista machine outside of work, I can’t determine whether this particular ‘quirk’ is because of my employer’s security configuration of Vista or Vista itself.

Suffice to say, I am quite stumped.

EDIT:

I would like to thank everyone for their responses. I used the Process Monitor suggested by Christian and found that the Windows Vista SearchIndexer and TortoiseSVN’s TSVNCache processes were trying to access the target file while my code was running, as suggested by Martin.

Thanks again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:57:03+00:00Added an answer on May 11, 2026 at 5:57 pm

    Do you have any virus scanners? Try to disable them or watch the file activity with ProcMon from http://www.sysinternals.com

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.