Skip to content

UnauthorizedAccessException when debugging test Compile to Assembly from the Test Explorer in VS #10887

@ScottHutchinson

Description

@ScottHutchinson

The executeProcess function is called with the workingDir parameter = "".

Somehow the working directory is defaulting to C:\Windows\System32 when the workingDir parameter = "", which causes an exception from the lines below.

    #if DEBUG
            File.WriteAllLines(Path.Combine(workingDir, "StandardOutput.txt"), outputList)
            File.WriteAllLines(Path.Combine(workingDir, "StandardError.txt"), errorsList)
    #endif

An exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll but was not handled in user code
Access to the path 'C:\Windows\System32\StandardOutput.txt' is denied.

Some other tests are also affected.

We need to default the working directory to the assembly location. Maybe like this:

    #if DEBUG
            let workingDir' =
                if workingDir = ""
                then
                    let executionLocation = Assembly.GetExecutingAssembly().Location
                    Path.GetDirectoryName executionLocation
                else
                    workingDir

            File.WriteAllLines(Path.Combine(workingDir', "StandardOutput.txt"), outputList)
            File.WriteAllLines(Path.Combine(workingDir', "StandardError.txt"), errorsList)
    #endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-TestingBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions