question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using SourceGenerators leads to CS0016 when path is too long

See original GitHub issue

Version 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:

  1. Clone https://github.com/SonarSource/sonar-dotnet into path that is at least 45 character long. For example
C:\Projects\.Community\Xxxxxxx sonar-dotnet
  1. Open analyzers\SonarAnalyzer.sln
  2. 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:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
pavel-mikula-sonarsourcecommented, Jul 20, 2022

I confirmed that the registry hack solved the problem.

Díky

0reactions
PeterHevesicommented, May 26, 2023

Or what if Long Paths are always enabled for everybody in Windows?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found