dotnet/BenchmarkDotNet

Generate Exception: Access to the path '...' is denied.

msschl opened this issue · 7 comments

When running BenchmarkDotNet with project files located on a second drive (SSD W:/) BenchmarkDotNet fails with Generate Exception: Access to the path 'W:\System Volume Information' is denied.

But when I copy all project files for example on my C:/ drive on my Desktop and run dotnet run -c Release there, then the benchmark runs without any problems...

λ dotnet --info
.NET SDK (reflecting any global.json):
 Version:   5.0.201
 Commit:    a09bd5c86c

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19042
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.201\

Host (useful for support):
  Version: 5.0.4
  Commit:  f27d337295

.NET SDKs installed:
  2.1.814 [C:\Program Files\dotnet\sdk]
  3.1.407 [C:\Program Files\dotnet\sdk]
  5.0.103 [C:\Program Files\dotnet\sdk]
  5.0.200-preview.21077.7 [C:\Program Files\dotnet\sdk]
  5.0.201 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download
W:\test\microbenchmarks
λ dotnet run -c Release
Available Benchmarks:
  #0 BCDToInt32ConverterBenchmark
  #1 CharToKeyBenchmark
  #2 Int32ToBCDConverterBenchmark
  #3 ManufactureCodeConverterBenchmark
  #4 NormalizeStringBenchmark
  #5 ValidCharBenchmark
  #6 TransmuteObjectBenchmark


You should select the target benchmark(s). Please, print a number of a benchmark (e.g. `0`) or a contained benchmark caption (e.g. `BCDToInt32ConverterBenchmark`).
If you want to select few, please separate them with space ` ` (e.g. `1 2 3`).
You can also provide the class name in console arguments by using --filter. (e.g. `--filter *BCDToInt32ConverterBenchmark*`).
ManufactureCodeConverterBenchmark

// Validating benchmarks:
// ***** BenchmarkRunner: Start   *****
// ***** Found 2 benchmark(s) in total *****
// ***** Building 1 exe(s) in Parallel: Start   *****
// ***** Done, took 00:00:00 (0.11 sec)   *****
// Found 2 benchmarks:
//   ManufactureCodeConverterBenchmark.PlexItCoverter_BigByteToString: DefaultJob
//   ManufactureCodeConverterBenchmark.ToManufactureCode: DefaultJob

// Generate Exception: Access to the path 'W:\System Volume Information' is denied.

// Generate Exception: Access to the path 'W:\System Volume Information' is denied.

// ***** BenchmarkRunner: Finish  *****

// * Export *
  C:\tmp\results\Benchmarks.MicroBenchmarks.ManufactureCodeConverterBenchmark-report.csv
  C:\tmp\results\Benchmarks.MicroBenchmarks.ManufactureCodeConverterBenchmark-report-github.md
  C:\tmp\results\Benchmarks.MicroBenchmarks.ManufactureCodeConverterBenchmark-report.html

// * Detailed results *
ManufactureCodeConverterBenchmark.PlexItCoverter_BigByteToString: DefaultJob
Runtime = ; GC =
There are not any results runs

ManufactureCodeConverterBenchmark.ToManufactureCode: DefaultJob
Runtime = ; GC =
There are not any results runs

// * Summary *

BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19042
Intel Core i7-6800K CPU 3.40GHz (Skylake), 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=5.0.201
  [Host] : .NET Core 5.0.4 (CoreCLR 5.0.421.11614, CoreFX 5.0.421.11614), X64 RyuJIT


|                         Method | Mean | Error | Ratio | RatioSD |
|------------------------------- |-----:|------:|------:|--------:|
| PlexItCoverter_BigByteToString |   NA |    NA |     ? |       ? |
|              ToManufactureCode |   NA |    NA |     ? |       ? |

Benchmarks with issues:
  ManufactureCodeConverterBenchmark.PlexItCoverter_BigByteToString: DefaultJob
  ManufactureCodeConverterBenchmark.ToManufactureCode: DefaultJob

// * Warnings *
BaselineCustomAnalyzer
  Summary -> A question mark '?' symbol indicates that it was not possible to compute the (Ratio, RatioSD) column(s) because the baseline value is too close to zero.

// * Legends *
  Mean    : Arithmetic mean of all measurements
  Error   : Half of 99.9% confidence interval
  Ratio   : Mean of the ratio distribution ([Current]/[Baseline])
  RatioSD : Standard deviation of the ratio distribution ([Current]/[Baseline])
  1 ns    : 1 Nanosecond (0.000000001 sec)

// * Diagnostic Output - MemoryDiagnoser *


// ***** BenchmarkRunner: End *****
// ** Remained 0 benchmark(s) to run **
Run time: 00:00:00 (0.25 sec), executed benchmarks: 0

Global total time: 00:00:00 (0.37 sec), executed benchmarks: 0
// * Artifacts cleanup *

Benchmarks.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net5.0</TargetFramework>
    <OutputType>Exe</OutputType>
    <IsPackable>false</IsPackable>
    <IsTestProject>false</IsTestProject>
  </PropertyGroup>

  <PropertyGroup>
    <LangVersion>9.0</LangVersion>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
  </ItemGroup>

</Project>

Program.cs

using BenchmarkDotNet.Running;

namespace Benchmarks
{
    public class Program
    {
        public static void Main(string[] args) =>
            BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
    }
}

ManufactureCodeConverterBenchmark.cs

using System;
using System.Collections.Generic;

using BenchmarkDotNet.Attributes;

namespace Benchmarks.MicroBenchmarks
{
    [MemoryDiagnoser]
    public class ManufactureCodeConverterBenchmark
    {
        public static readonly byte[] TEST_BYTES_LITTLE_ENDIAN = new byte[] { 0x97, 0x26 };

        public const int Iterations = 100_000;

        [Benchmark(Description = "PlexItCoverter_BigByteToString", Baseline = true, OperationsPerInvoke = Iterations)]
        public void PlexItCoverter_BigByteToString()
        {
            for (var i = 0; i < Iterations; i++)
                _ = BigByteToString(TEST_BYTES_LITTLE_ENDIAN);
        }

        [Benchmark(Description = "ToManufactureCode", OperationsPerInvoke = Iterations)]
        public void ToManufactureCode()
        {
            for (var i = 0; i < Iterations; i++)
                _ = ToManufactureCode(TEST_BYTES_LITTLE_ENDIAN);
        }

        private static string ToManufactureCode(byte[] data)
        {
            if (data.Length != 2)
                throw new ArgumentException("The three letter manufacture code requires two bytes.", nameof(data));

            return String.Create<byte[]>(3, data, (span, data) =>
            {
                // Get the first five bits from the first byte (byte zero)
                var c3 = data[0] & 0x1F;

                // Get the remaining three bits of the first byte (byte zero) and two bits of the second byte (byte one)
                var c2 = ((data[0] >> 5) | (data[1] << 3)) & 0x1F;

                // Get the next five bits from the second byte (byte one)
                var c1 = (data[1] >> 2) & 0x1F;

                // Convert bits to characters by adding 64 back and casting to char
                span[2] = (char)(c3 + 64);
                span[1] = (char)(c2 + 64);
                span[0] = (char)(c1 + 64);
            });
        }

        public static string BigByteToString(byte[] bData)
        {
            // Daten jetzt in einen Integer wandeln
            int iValue = (bData[1] * 256) + bData[0];

            byte[] bChars = new byte[3];

            // Intwert auf 5Bit Basis zerlegen
            bChars[0] = (byte)(iValue / 1024);
            bChars[1] = (byte)((iValue - bChars[0] * 1024) / 32);
            bChars[2] = (byte)(iValue - bChars[0] * 1024 - bChars[1] * 32);

            // Jetzt noch 64 Addieren für die korrekte Verschiebung
            bChars[0] += 64;
            bChars[1] += 64;
            bChars[2] += 64;

            // Jetzt einen String aus den drei Chars erstellen
            // return plexxIT.Portable.Convert.CConvert.convertByteArraytoString(bChars);
            return System.Text.Encoding.Default.GetString(bChars);
        }
    }
}

Hi @msschl

I suspect that the exception comes from this method that tries to search for solution and project file:

var projectFile = rootDirectory
.EnumerateFiles("*.*", SearchOption.AllDirectories)
.FirstOrDefault(file => possibleNames.Contains(file.Name));

Could you please try to run the following example and see if it's also going to fail?

using System;
using System.IO;
using System.Linq;

namespace Repro
{
    class Program
    {
        static void Main()
        {
            var projectFile = new DirectoryInfo(@"W:\")
                .EnumerateFiles("*.*", SearchOption.AllDirectories)
                .FirstOrDefault(file => file.Name.Equals("whatever"));

            Console.WriteLine(projectFile == default);
        }
    }
}

@adamsitnik Yes, it fails as well.

$ dotnet run -c Release
Unhandled exception. System.UnauthorizedAccessException: Access to the path 'W:\System Volume Information' is denied.
   at System.IO.Enumeration.FileSystemEnumerator`1.CreateRelativeDirectoryHandle(ReadOnlySpan`1 relativePath, String fullPath)
   at System.IO.Enumeration.FileSystemEnumerator`1.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at Benchmarks.Program.Main(String[] args) in W:\test\microbenchmarks\Program.cs:line 11

How would I fix this issue? @adamsitnik

A friendly ping ✋🏽

How would I fix this issue? @adamsitnik

How would I fix this issue? @adamsitnik

I was given the same error message but for my Application Data folder. I was running from my home folder by stating the full path to the executable.

The error went away after I cd'd into it the benchmark folder.

Same issue with "Application Data" folder but only on my work laptop running Windows, personal PC with linux runs fine.
Heres a quick console application trying

using BenchmarkDotNet.Running;
using BenchmarkDotNet.Attributes;

BenchmarkRunner.Run<Benchmark>();
return;

public class Benchmark
{
	[Benchmark]
	public void FirstTest()
	{
		World w = new();
		w.SayHi(1000);
	}
}

public class World
{
	public string SayHi(int a){
		string test = "";
		for(int i =0; i<a; i++){
			test+="Hello World\n";
		}
		return test;
	}

}
// Validating benchmarks:
// ***** BenchmarkRunner: Start   *****
// ***** Found 1 benchmark(s) in total *****
// ***** Building 1 exe(s) in Parallel: Start   *****
// ***** Done, took 00:00:00 (0.05 sec)   *****
// Found 1 benchmarks:
//   Benchmark.FirstTest: DefaultJob

Setup power plan (GUID: $GUID FriendlyName: High performance)
// Generate Exception: Access to the path 'C:\Users\USER\Application Data' is denied.

// BenchmarkDotNet has failed to build the auto-generated boilerplate code.
// It can be found in C:\Users\USER\repos\benchmark-test\bin\Release\net6.0\e1592339-3155-46da-8202-8920a0a0e4ed
// Please follow the troubleshooting guide: https://benchmarkdotnet.org/articles/guides/troubleshooting.html

// ** Remained 0 (0.0%) benchmark(s) to run. Estimated finish 2023-02-21 15:59 (0h 0m from now) **
Successfully reverted power plan (GUID: $GUID FriendlyName: Balanced)
// ***** BenchmarkRunner: Finish  *****

// * Export *
  BenchmarkDotNet.Artifacts\results\Benchmark-report.csv
  BenchmarkDotNet.Artifacts\results\Benchmark-report-github.md
  BenchmarkDotNet.Artifacts\results\Benchmark-report.html

// * Detailed results *
Benchmark.FirstTest: DefaultJob
Runtime = ; GC = 
There are not any results runs

Here's my dotnet --info

.NET SDK (reflecting any global.json):
 Version:   6.0.405
 Commit:    27ab36058b

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19044
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.405\

Host:
  Version:      7.0.2
  Architecture: x64
  Commit:       d037e070eb

.NET SDKs installed:
  5.0.408 [C:\Program Files\dotnet\sdk]
  6.0.308 [C:\Program Files\dotnet\sdk]
  6.0.400 [C:\Program Files\dotnet\sdk]
  6.0.405 [C:\Program Files\dotnet\sdk]
  7.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  C:\Users\USER\global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

My project doesn't have a solution file, adding one solved the issue

dotnet new solution