Home > database >  Error when the filepath for a generated file for a Blazor component is too long
Error when the filepath for a generated file for a Blazor component is too long

Time:09-29

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

CodePudding user response:

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)

  • Related