VisualStudio PathTooLongException

1k Views Asked by At

I have run into issues with VisualStudio - both 2017 Pro and 2019 Pro. If I try to open my solution, I get this error:

enter image description here

The error message in VS2019 is a bit different but with the same meaning. As I investigated the ActivityLog file, there is only this node interesting regarding this issue:

<entry>
<record>698</record>
<time>2019/07/03 08:14:00.064</time>
<type>Error</type>
<source>Editor or Editor Extension</source>
<description>System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.&#x000D;&#x000A;
at System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32  maxPathLength, Boolean expandShortPaths)&#x000D;&#x000A;
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)&#x000D;&#x000A;
   at System.IO.Path.InternalGetDirectoryName(String path)&#x000D;&#x000A;
   at Microsoft.VisualStudio.ErrorListPkg.PathColumnDefinition.GetCachedDirectoryName(ITableEntryHandle entry)&#x000D;&#x000A;
   at Microsoft.VisualStudio.ErrorListPkg.PathColumnDefinition.TryCreateStringContent(ITableEntryHandle entry, Boolean truncatedText, Boolean singleColumnView, String&amp; content)&#x000D;&#x000A;
   at Microsoft.VisualStudio.Shell.TableControl.TableEntryHandleExtensions.TryCreateStringContent(ITableEntryHandle entry, ITableColumnDefinition column, Boolean truncatedText, Boolean singleColumnView, String&amp; content)&#x000D;&#x000A;
   at Microsoft.VisualStudio.Shell.TableControl.Implementation.TableControl.GenerateFiltersForColumn(UpdateResults results, ITableColumnDefinition columnDefinition)&#x000D;&#x000A;
   at Microsoft.VisualStudio.Shell.TableControl.Implementation.TableControl.UpdateEntryFilters(UpdateResults results, HashSet`1 variableColumns)&#x000D;&#x000A;
   at Microsoft.VisualStudio.Shell.TableControl.Implementation.TableControl.UpdateEntries(HashSet`1 variableColumns, Boolean anyColumnChanges, List`1&amp; frozenSinksAwaitingDisposal)&#x000D;&#x000A;
   at Microsoft.VisualStudio.Shell.TableControl.Implementation.TableControl.&lt;UpdateEntriesAsync&gt;d__182.MoveNext()&#x000D;&#x000A;
--- End of stack trace from previous location where exception was thrown ---&#x000D;&#x000A;
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)</description>
</entry>

Is there any way how to figure out exactly what path is wrong? I suspected that SpecFlow addid had been causing this issue. But if I disable this addon, nothing changes.

Another teammate does not have this issue with the same solution.

3

There are 3 best solutions below

0
On BEST ANSWER

I somehow got rid of this error message. I don't understand how, but let me share steps I did.

  1. I started removing projects from solution one by one to figure out what project causes the issue.
  2. Once I found the bad one, I reverted all the changes on GIT.

  3. I repeated this approach for files and folders within this project. As I deleted some files and restarted the VS, the problem disappeared.

  4. Again reverted all changes on GIT.

  5. Voila, the error is history in both 2017 and 2019. Nothing changed in SLN or CSPROJ files.

0
On

Since my paths are rather long, I ran into a few of these PathTooLongExceptions as well. This is esp. the case when the VS project uses relative paths. Obviously making paths shorter will resolve a lot of these.

But before doing this rather time consuming overhaul of your development environment, there are some things you could do:

  1. Use symbolic links or junctions with a shorter path (e.g. mklink /J M.E.D.A Microsoft.Extensions.DependencyInjection.Abstractions) and use these in your project file
  2. Use Absolute paths: relative paths can become really long behind the scenes as Visual Studio may refer to %(FullPath) which rather rapidly goes beyond 260 Chars

The above resolved my issues.

0
On

Windows, inherited from MS-DOS, a very short maximum path length when using the simple APIs. Many applications have fixed buffers to this size – look for MAX_PATH – and thus no easy way to make things longer. 248 characters was a lot when 10MB was a typical HDD size.

NTFS and Win32 can support much longer paths (215-1 characters), but requires using APIs in the right way. Which many, even actively developed ones, do not.

I doubt Visual Studio, even in its latest version, let alone all extensions, have been fully updated to handle long paths.

Check you avoid a long path at the root of your solution (Visual Studio's default project location does not help here).