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 thrown if .csproj file is read-only #859

Closed
FredAtIvory opened this issue Mar 26, 2024 · 3 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@FredAtIvory
Copy link

FredAtIvory commented Mar 26, 2024

Upgraded from 2.7.0 to 3.05 and getting System.UnauthorizedAccessException when CycloneDX attempts to open a read-only .csproj file.

I am specifying a .sln file on the command line which references multiple .csproj files. I I make the .cs

Windows 10 and 11, .NET 8.0

This seems like new behavior since 2.7.0 works fine on the same .sln/.csproj file set. I expect it to be able to parse the .csproj file even if it is read-only.

I am passing a .sln file on the command line which references several .csproj files. My .csproj files are RO. If I make one RW, 3.0.5 will open it, but then the exception is thrown on the next .csproj file which is RO.

This happens in ProjectFileService.cs: line 92, possibly added with -ipr feature.

91 XmlDocument xmldoc = new XmlDocument();
92 using var fileStream = _fileSystem.FileStream.New(projectFilePath, FileMode.Open);
93 xmldoc.Load(fileStream);

Stack trace:

Unhandled exception: System.UnauthorizedAccessException: Access to the path 'C:\my-app\my-project.csproj' is denied.
at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable1 unixCreateMode)
at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable1 unixCreateMode)
at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable1 unixCreateMode)
at System.IO.FileStream..ctor(String path, FileMode mode)
at System.IO.Abstractions.FileStreamFactory.New(String path, FileMode mode)
at CycloneDX.Services.ProjectFileService.GetProjectNameAndVersion(String projectFilePath) in /home/runner/work/cyclonedx-dotnet/cyclonedx-dotnet/CycloneDX/Services/ProjectFileService.cs:line 92
at CycloneDX.Services.ProjectFileService.RecursivelyGetProjectReferencesAsync(String projectFilePath) in /home/runner/work/cyclonedx-dotnet/cyclonedx-dotnet/CycloneDX/Services/ProjectFileService.cs:line 331
at CycloneDX.Services.SolutionFileService.GetSolutionProjectReferencesAsync(String solutionFilePath) in /home/runner/work/cyclonedx-dotnet/cyclonedx-dotnet/CycloneDX/Services/SolutionFileService.cs:line 73
at CycloneDX.Services.SolutionFileService.GetSolutionDotnetDependencys(String solutionFilePath, String baseIntermediateOutputPath, Boolean excludeTestProjects, String framework, String runtime) in /home/runner/work/cyclonedx-dotnet/cyclonedx-dotnet/CycloneDX/Services/SolutionFileService.cs:line 99
at CycloneDX.Runner.HandleCommandAsync(RunOptions options) in /home/runner/work/cyclonedx-dotnet/cyclonedx-dotnet/CycloneDX/Runner.cs:line 167
at CycloneDX.Program.<>c__DisplayClass0_0.<

b__2>d.MoveNext() in /home/runner/work/cyclonedx-dotnet/cyclonedx-dotnet/CycloneDX/Program.cs:line 137

@github-actions github-actions bot added the triage Don't know what to do with this yet label Mar 26, 2024
@mtsfoni mtsfoni added bug Something isn't working and removed triage Don't know what to do with this yet labels Mar 26, 2024
@mtsfoni
Copy link
Contributor

mtsfoni commented Mar 26, 2024

Hello Fred,

thanks for reporting the issue. I could reproduce it and prepared a fix at #860. There are one or two other things that need fixes, and I'd like to bundle them. I'd say you can expect a new Version with the fix in the next 48 hours.

@mtsfoni mtsfoni self-assigned this Mar 26, 2024
@mtsfoni
Copy link
Contributor

mtsfoni commented Mar 28, 2024

Release is out. I'd appreciate feedback if it works for you as expected.

@mtsfoni mtsfoni closed this as completed Mar 28, 2024
@FredAtIvory
Copy link
Author

FredAtIvory commented Apr 5, 2024

confirmed working in 3.0.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants