dotnet / project-system

The .NET Project System for Visual Studio
MIT License
968 stars 386 forks source link

Prevent fault in ImportTreeProvider #9355

Closed drewnoakes closed 9 months ago

drewnoakes commented 9 months ago

We had a report of an error with this stack:

System.AggregateException: Project system data flow 'Import Tree Action: 30768406' closed because of an exception: 'path' cannot be an empty string ("") or start with the null character.
Parameter name: path.
---> (Inner Exception #0) System.ArgumentException: 'path' cannot be an empty string ("") or start with the null character.
Parameter name: path
   at Microsoft.Requires.NotNullOrEmpty(String value, String parameterName)
   at Microsoft.VisualStudio.ProjectSystem.PathHelper.EnsureTrailingSlash(String path)
   at Microsoft.VisualStudio.ProjectSystem.Tree.ProjectImports.ImportTreeProvider.<set_ShowAllFiles>g__SyncTree|22_5(IProjectVersionedValue`1 e)
   at Microsoft.VisualStudio.ProjectSystem.ActionBlockSlimSync`1.ProcessInputAsync(TInput input)
   at Microsoft.VisualStudio.ProjectSystem.DataReceivingBlockSlim`1.<ProcessInputQueueAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.VisualStudio.ProjectSystem.CommonProjectSystemTools.Rethrow(Exception ex)
   at Microsoft.VisualStudio.ProjectSystem.ExceptionFilter.<>c__DisplayClass2_0.<Guard>g__Action|0()
   at GuardMethodClass.GuardMethod(Func`1 , Func`2 , Func`2 )
<--- (Inner Exception #0)

The problem seems to actually be in the ProjectFileClassifier, where we checked for null but not empty strings. The call to EnsureTrailingSlash would throw on either. We need to check for both.

This fixes that.

Microsoft Reviewers: Open in CodeFlow