Using SourceGenerators leads to CS0016 when path is too long
See original GitHub issueVersion Used: 4.2.0-4.22281.5 (8d3180e5) Also observed on some previous 4.2.* versions I’m not sure when I updated to 4.1.* I think it was working on 4.0.*
Steps to Reproduce:
- Clone https://github.com/SonarSource/sonar-dotnet into path that is at least 45 character long. For example
C:\Projects\.Community\Xxxxxxx sonar-dotnet
- Open
analyzers\SonarAnalyzer.sln
- Try to build it
Expected Behavior:
Project should build. Just as it builds on shorter path like
C:\Projects\sonar-dotnet
Actual Behavior:
Build fails. Our project uses Source Generators from StyleCop that generates dozens of files. These 7 files have path longer than 256 characters and fails to be generated.
3>------ Build started: Project: SonarAnalyzer.CFG, Configuration: Debug Any CPU ------
3>CSC : error CS0016: Could not write to output file 'D:\Projects\.Community\Xxxxxxx sonar-dotnet\analyzers\src\SonarAnalyzer.CFG\obj\Debug\net46\generated\SonarAnalyzer.ShimLayer.CodeGeneration\StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator\FunctionPointerUnmanagedCallingConventionListSyntaxWrapper.g.cs' -- 'Could not find a part of the path 'D:\Projects\.Community\Xxxxxxx sonar-dotnet\analyzers\src\SonarAnalyzer.CFG\obj\Debug\net46\generated\SonarAnalyzer.ShimLayer.CodeGeneration\StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator\FunctionPointerUnmanagedCallingConventionListSyntaxWrapper.g.cs'.'
3>Done building project "SonarAnalyzer.CFG.csproj" -- FAILED.
3>CSC : error CS0016: Could not write to output file 'D:\Projects\.Community\Xxxxxxx sonar-dotnet\analyzers\src\SonarAnalyzer.CFG\obj\Debug\netstandard2.0\generated\SonarAnalyzer.ShimLayer.CodeGeneration\StyleCop.Analyzers.CodeGeneration.OperationLightupGenerator\IObjectOrCollectionInitializerOperationWrapper.g.cs' -- 'Could not find a part of the path 'D:\Projects\.Community\Xxxxxxx sonar-dotnet\analyzers\src\SonarAnalyzer.CFG\obj\Debug\netstandard2.0\generated\SonarAnalyzer.ShimLayer.CodeGeneration\StyleCop.Analyzers.CodeGeneration.OperationLightupGenerator\IObjectOrCollectionInitializerOperationWrapper.g.cs'.'
3>CSC : error CS0016: Could not write to output file 'D:\Projects\.Community\Xxxxxxx sonar-dotnet\analyzers\src\SonarAnalyzer.CFG\obj\Debug\netstandard2.0\generated\SonarAnalyzer.ShimLayer.CodeGeneration\StyleCop.Analyzers.CodeGeneration.OperationLightupGenerator\ICollectionElementInitializerOperationWrapper.g.cs' -- 'Could not find a part of the path 'D:\Projects\.Community\Xxxxxxx sonar-dotnet\analyzers\src\SonarAnalyzer.CFG\obj\Debug\netstandard2.0\generated\SonarAnalyzer.ShimLayer.CodeGeneration\StyleCop.Analyzers.CodeGeneration.OperationLightupGenerator\ICollectionElementInitializerOperationWrapper.g.cs'.'
3>CSC : error CS0016: Could not write to output file 'D:\Projects\.Community\Xxxxxxx sonar-dotnet\analyzers\src\SonarAnalyzer.CFG\obj\Debug\netstandard2.0\generated\SonarAnalyzer.ShimLayer.CodeGeneration\StyleCop.Analyzers.CodeGeneration.OperationLightupGenerator\IStaticLocalInitializationSemaphoreOperationWrapper.g.cs' -- 'Could not find a part of the path 'D:\Projects\.Community\Xxxxxxx sonar-dotnet\analyzers\src\SonarAnalyzer.CFG\obj\Debug\netstandard2.0\generated\SonarAnalyzer.ShimLayer.CodeGeneration\StyleCop.Analyzers.CodeGeneration.OperationLightupGenerator\IStaticLocalInitializationSemaphoreOperationWrapper.g.cs'.'
3>CSC : error CS0016: Could not write to output file 'D:\Projects\.Community\Xxxxxxx sonar-dotnet\analyzers\src\SonarAnalyzer.CFG\obj\Debug\netstandard2.0\generated\SonarAnalyzer.ShimLayer.CodeGeneration\StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator\FunctionPointerUnmanagedCallingConventionListSyntaxWrapper.g.cs' -- 'Could not find a part of the path 'D:\Projects\.Community\Xxxxxxx sonar-dotnet\analyzers\src\SonarAnalyzer.CFG\obj\Debug\netstandard2.0\generated\SonarAnalyzer.ShimLayer.CodeGeneration\StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator\FunctionPointerUnmanagedCallingConventionListSyntaxWrapper.g.cs'.'
3>CSC : error CS0016: Could not write to output file 'D:\Projects\.Community\Xxxxxxx sonar-dotnet\analyzers\src\SonarAnalyzer.CFG\obj\Debug\netstandard2.0\generated\SonarAnalyzer.ShimLayer.CodeGeneration\StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator\FunctionPointerUnmanagedCallingConventionSyntaxWrapper.g.cs' -- 'Could not find a part of the path 'D:\Projects\.Community\Xxxxxxx sonar-dotnet\analyzers\src\SonarAnalyzer.CFG\obj\Debug\netstandard2.0\generated\SonarAnalyzer.ShimLayer.CodeGeneration\StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator\FunctionPointerUnmanagedCallingConventionSyntaxWrapper.g.cs'.'
3>CSC : error CS0016: Could not write to output file 'D:\Projects\.Community\Xxxxxxx sonar-dotnet\analyzers\src\SonarAnalyzer.CFG\obj\Debug\netstandard2.0\generated\SonarAnalyzer.ShimLayer.CodeGeneration\StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator\ImplicitStackAllocArrayCreationExpressionSyntaxWrapper.g.cs' -- 'Could not find a part of the path 'D:\Projects\.Community\Xxxxxxx sonar-dotnet\analyzers\src\SonarAnalyzer.CFG\obj\Debug\netstandard2.0\generated\SonarAnalyzer.ShimLayer.CodeGeneration\StyleCop.Analyzers.CodeGeneration.SyntaxLightupGenerator\ImplicitStackAllocArrayCreationExpressionSyntaxWrapper.g.cs'.'
3>Done building project "SonarAnalyzer.CFG.csproj" -- FAILED.
Note: I’m sure this was working fine before on the same path. Last time I worked with this path was around 01/2022
Issue Analytics
- State:
- Created a year ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Error when the filepath for a generated file for a Blazor ...
The problem is that the filepath of the generated Razor file is too long, over 260 characters to be exact (more on why...
Read more >CSProj - NET5: Unable to create project with path length ...
With a project where the path to the csproj is (including the csproj filename) is greater than 259 char, in VS, if I:...
Read more >Search existing Visual Studio feedback
After updated Visual Studio to 17.6.5, our project will no longer compile. It reports an error related to the source generators:
Read more >CS0016: Could not write to output file 'c:\..\..\ ...
So something is trying to create and use that folder and failing with The directory name is invalid. Try looking at the configuration...
Read more >"The path is more than 244 characters which is too long ...
The operation would result in a path that is too long. The path must be no more than 244 characters.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I confirmed that the registry hack solved the problem.
Díky
Or what if Long Paths are always enabled for everybody in Windows?