1

I am trying to create a Component in Blazor server application but I get this error:

Severity Code Description Project File Line Suppression State Error CS0016 Could not write to output file 'C:\Users\UserName\Documents\Projects\FolderProject\ProjectName\obj\Debug\net6.0\generated\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Components_Pages_HRM_Xxxxxxxxxxxxxxx_razor.g.cs' -- 'Could not find a part of the path 'C:\Users\UserName\Documents\Projects\FolderProject\ProjectName\obj\Debug\net6.0\generated\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Components_Pages_HRM_Xxxxxxxxxxxxxxx_razor.g.cs'.' ProjectName C:\Users\UserName\Documents\Projects\FolderProject\ProjectName\CSC 1 Active.

I tried to created a new project and add the same component name, that works perfect, even in for separate Blazor components library, it works fine. If I Delete just one character x from this name, then the application works fine again!.
Can some explain to me way?
Note: My path component: application root => folder [component] => folder [Pages] => folder [HRM] => MyBlazorComponent.razor

MindSwipe
  • 7,193
  • 24
  • 47
Nb777
  • 1,658
  • 8
  • 27
  • 1
    Could be that the filepath is too long, the solution for that would be to move the solution folder to something like `C:\Projects\[your solution name here]` – MindSwipe Sep 29 '22 at 07:56
  • @MindSwipe, thanks a lot, I think you are right, this solve the problem, but I can not move the application right now to another folder, I have to work in this folder because the whole teams and projects are here, do you have another solution ? – Nb777 Sep 29 '22 at 08:05
  • Use a shorter path is probably the solution with the least repercussions, alternatively you can follow an online guide on "How to make Windows 10 accept file paths over 260 characters". What do you mean "the whole teams and projects are here", is this a shared folder? If so, then don't do that, use a proper version control system like git. – MindSwipe Sep 29 '22 at 08:12
  • @MindSwipe, Thanks a lot, `How to make Windows 10 accept file paths over 260 characters` was the solution, Could you please add this answer, or I will add it ! – Nb777 Sep 29 '22 at 08:32
  • 1
    I edited your question to make it a little more broad so if anyone comes across this again they will hopefully find this. Take a look at the edit and if you disagree with anything you can roll it back or amend my edit. – MindSwipe Sep 29 '22 at 08:57

1 Answers1

1

The problem is that the filepath of the generated Razor file is too long, over 260 characters to be exact (more on why this number here). The solution is either to move the solution to a folder where the filepath length won't/ doesn't exceed 260 characters (something like C:\Projects\[your solution folder]).

Alternatively you can make Windows (newer than Windows 10 version 1607) accept paths over 260 characters by enabling long paths, you can do this by setting the registry key LongPathsEnabled in Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem to 1. (Also explained in this How-To Geek article)

MindSwipe
  • 7,193
  • 24
  • 47