Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.UnauthorizedAccessException when running Stryker #272

Closed
royto opened this issue Dec 4, 2018 · 9 comments · Fixed by #295
Closed

System.UnauthorizedAccessException when running Stryker #272

royto opened this issue Dec 4, 2018 · 9 comments · Fixed by #295

Comments

@royto
Copy link
Contributor

royto commented Dec 4, 2018

Version: 0.7.0 (beta)

On running dotnet stryker on my unit test project (.NET Core 2.0), I encountered the following issue

[17:40:22 ERR] An error occurred during the mutation test run
System.UnauthorizedAccessException: Access to the path 'C:\Repos\MyProject\src\Tests\MyProject.UnitTests\bin\Debug\netcoreapp2.0\Services.dll' is denied.
   at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle)
   at System.IO.FileStream.CreateFileOpenHandle(FileMode mode, FileShare share, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.Abstractions.FileWrapper.Create(String path)
   at Stryker.Core.MutationTest.MutationTestProcess.Mutate()
   at Stryker.Core.StrykerRunner.RunMutationTest(StrykerOptions options)
[17:40:22 INF] Time Elapsed 00:00:39.8056808

I have multiple project reference (in .NET Standard 2.0) and I specify one of them with the --project-file option

dotnet stryker --project-file=..\..\Services\Services.csproj

@richardwerkman
Copy link
Member

I haven't seen this error before. It looks like the file could be locked or your console doesn't have the correct rights to open the file. Could you try to run stryker from a console with administration rights? Or try to clean the solution and rerun?

If the error keeps occuring we'll look further into this.

@royto
Copy link
Contributor Author

royto commented Dec 5, 2018

Same error with cmd in Admin mode.

I have tried with another project on the same machine and it works ...

I'll try to ask somebody else if he add the same issue on this project

@royto
Copy link
Contributor Author

royto commented Dec 6, 2018

I have tried on my colleague machine and he has the same issue ...

@richardwerkman
Copy link
Member

Could it be that the file is somehow marked as readonly?

I found in the documentation for System.IO.File.Create that this exception can only come from:

The caller does not have the required permission.

-or-

path specified a file that is read-only.

@richardwerkman
Copy link
Member

@royto Any update? I would like to close the issue if it was indeed a readonly property.

We could add a warning log that hints users to check for permissions and read-only propertys on the file the exception occurs on. But I would like to know for sure if this was the issue first.

@royto
Copy link
Contributor Author

royto commented Dec 12, 2018

I found the issue. \o/

It was relative to a configuration in my csproj.

I had this line :

   <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>

When it is set to false, the dll are generated into bin/debug and the folder netcoreapp2.0 was empty.

Stryker trying to generate in this folder, resulting to access denied error.

I set it to true and unit test dll was generated into bin/Debug/netcoreapp2.0.
I do not have the error anymore and stryker working well ...

I think that stryker should look for this property and use bin/Debug or bin/Debug/FrameworkVersion depending of the AppendTargetFrameworkToOutputPath property value.

@richardwerkman
Copy link
Member

Ah interesting! To be honest I was not aware of the AppendTargetFrameworkToOutputPath property for projects. We should indeed take this into account.

Could you create a PR for this? Or should we create an issue for others to pick up.

@royto
Copy link
Contributor Author

royto commented Dec 13, 2018

I'm working on it. PR will be created soon I hope ...

@richardwerkman
Copy link
Member

Awesome! Looking forward to it 👍

royto pushed a commit to royto/stryker-net that referenced this issue Dec 13, 2018
If present and true or absent, build generate files to bin/Mode/targetFramework (ex: /bin/Deug/netcoreapp2.0)
Is set to false, build generate file to bin/Mode (ex: bin/Debug)

this fix the issue when AppendTargetFrameworkToOutputPath is set to false resulting to an System.UnauthorizedAccessException

Fix stryker-mutator#272
@ghost ghost added the reviewing label Dec 13, 2018
richardwerkman pushed a commit that referenced this issue Dec 15, 2018
…sproj property is included (#295)

If present and true or absent, the mutated Assembly is written to bin/Mode/targetFramework (ex: `/bin/Debug/netcoreapp2.0`)
Is set to false, build generate file to bin/Mode (ex: `bin/Debug`)

Fix #272
@ghost ghost removed the reviewing label Dec 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants