dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.01k stars 4.03k forks source link

System.ArgumentNullException while opening .editorconfig file #53831

Closed vsfeedback closed 3 years ago

vsfeedback commented 3 years ago

This issue has been moved from a ticket on Developer Community.


[severity:It bothers me. A fix would be nice] When trying to open a .editorconfig file in one of my projects, I received a System.ArgumentNullException exception:

An error occurred while initializing the frame's content
System.ArgumentNullException: Value cannot be null.
Parameter name: path
   at System.IO.DirectoryInfo.. ctor(String path)
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Extensions.SolutionExtensions.<>c.<GetProjectsForPath>b__0_1(Project p)
   at System.Linq.Enumerable.<>c__DisplayClass7_0`3. <CombineSelectors>b__0(TSource x)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Extensions.SolutionExtensions.GetProjectsForPath(Solution solution, String givenPath)
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider.SettingsProviderBase`4.Update()
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider.Formatting.CommonFormattingSettingsProviderFactory.GetForFile(String filePath)
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider.CombinedOptionsProviderFactory`1.GetForFile(String filePath)
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.SettingsAggregator.GetSettingsProvider[TData](String fileName)
   at Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.SettingsEditorPane. <Initialize>g__GetFormattingView|12_0()
   at Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.SettingsEditorPane.Initialize()
   at Microsoft.VisualStudio.Shell.WindowPane.InternalSetSite(IServiceProvider p)
   at Microsoft.VisualStudio.Shell.WindowPane.Microsoft.VisualStudio.Shell.Interop.IVsWindowPane.SetSite(IServiceProvider psp)
   at Microsoft.VisualStudio.Shell.WindowPane.Microsoft.VisualStudio.Shell.Interop.IVsUIElementPane.SetUIElementSite(IServiceProvider p)
   at Microsoft.VisualStudio.Platform.WindowManagement.UIElementDocumentObject.SetSite(DocumentObjectSite site)
   at Microsoft.VisualStudio.Platform.WindowManagement.DocumentObjectSite.InitializeDocumentObject(Object punkView)
   at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.InitializeDocumentSite(Boolean creatingStubFrame, Boolean replacingStubView, Object punkView, Object punkData, IServiceProvider pServiceProvider, IVsUIHierarchy pUIHierarchy, UInt32 vsid)
   at Microsoft.VisualStudio.Platform.WindowManagement.WindowManagerService.CreateContentPane(FrameMoniker frameMoniker, Boolean isDocument, String lpstrMkDoc, UInt32 eCreateWindowFlags, Object punkView, Object punkData, IServiceProvider pServiceProvider, IVsUIHierarchy pUIHierarchy, UInt32 vsid, Guid rguidCmdUI, ViewGroup parent, IVsWindowFrame& ppWindowFrame)

Original Comments

Feedback Bot on 5/28/2021, 04:05 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Feedback Bot on 5/28/2021, 10:38 PM:

Thank you for sharing your feedback! Our teams prioritize action on product issues with broad customer impact. See details at: https://docs.microsoft.com/en-us/visualstudio/ide/report-a-problem?view=vs-2019#faq. In case you need answers to common questions or need assisted support, be sure to use https://visualstudio.microsoft.com/vs/support/. We’ll keep you posted on any updates to this feedback.


Original Solutions

(no solutions)

Eli-Black-Work commented 3 years ago

Thanks 🙂 Original error report was by me.

jmarolf commented 3 years ago

Cannot reproduce I believe this was already fixed

timritzer commented 3 years ago

@jmarolf Can still recreate this one. Recreation is pretty simple, have your editor config in a parent folder to the solution, and included in the solution.

Example: Repo Root .editorconfig Solution1 Solution1.sln Solution2 Solution2.sln

This will apply to both solutions, and is supported. However the editor will blow up when trying to edit it.

Moving it into the solution folder with the exact same content makes the error go away.

This is problematic for mono-repo's with consistent coding standards.

An error occurred while initializing the frame's content
System.ArgumentNullException: Value cannot be null.
Parameter name: path
   at System.IO.DirectoryInfo..ctor(String path)
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Extensions.SolutionExtensions.<>c.<GetProjectsForPath>b__0_1(Project p)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Extensions.SolutionExtensions.GetProjectsForPath(Solution solution, String givenPath)
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider.SettingsProviderBase`4.Update()
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider.Formatting.CommonFormattingSettingsProviderFactory.GetForFile(String filePath)
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider.CombinedOptionsProviderFactory`1.GetForFile(String filePath)
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.SettingsAggregator.GetSettingsProvider[TData](String fileName)
   at Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.SettingsEditorPane.<Initialize>g__GetFormattingView|12_0()
   at Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.SettingsEditorPane.Initialize()
   at Microsoft.VisualStudio.Shell.WindowPane.InternalSetSite(IServiceProvider p)
   at Microsoft.VisualStudio.Platform.WindowManagement.UIElementDocumentObject.SetSite(DocumentObjectSite site)
   at Microsoft.VisualStudio.Platform.WindowManagement.DocumentObjectSite.InitializeDocumentObject(Object punkView)
   at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.InitializeDocumentSite(Boolean creatingStubFrame, Boolean replacingStubView, Object punkView, Object punkData, IServiceProvider pServiceProvider, IVsUIHierarchy pUIHierarchy, UInt32 vsid)
   at Microsoft.VisualStudio.Platform.WindowManagement.WindowManagerService.CreateContentPane(FrameMoniker frameMoniker, Boolean isDocument, String lpstrMkDoc, UInt32 eCreateWindowFlags, Object punkView, Object punkData, IServiceProvider pServiceProvider, IVsUIHierarchy pUIHierarchy, UInt32 vsid, Guid rguidCmdUI, ViewGroup parent, IVsWindowFrame& ppWindowFrame)
jmarolf commented 3 years ago

thanks! let me try.

jmarolf commented 3 years ago

Confirmed this does not reproduce on the latest builds

syska commented 2 years ago

Latest stable: 17.0.4 Microsoft Visual Studio Community 2022 (64-bit)

An error occurred while initializing the frame's content
System.ArgumentNullException: Value cannot be null.
Parameter name: path
   at System.IO.DirectoryInfo..ctor(String path)
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Extensions.SolutionExtensions.<>c.<GetProjectsForPath>b__0_1(Project p)
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Extensions.SolutionExtensions.GetProjectsForPath(Solution solution, String givenPath)
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider.SettingsProviderBase`4.Update()
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider.Whitespace.CommonWhitespaceSettingsProviderFactory.GetForFile(String filePath)
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider.CombinedOptionsProviderFactory`1.GetForFile(String filePath)
   at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.SettingsAggregator.GetSettingsProvider[TData](String fileName)
   at Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.SettingsEditorPane.<>c__DisplayClass12_0.<Initialize>g__GetWhitespaceView|1()
   at Microsoft.VisualStudio.LanguageServices.EditorConfigSettings.SettingsEditorPane.Initialize()
   at Microsoft.VisualStudio.Shell.WindowPane.InternalSetSite(IServiceProvider p)
   at Microsoft.VisualStudio.Platform.WindowManagement.UIElementDocumentObject.SetSite(DocumentObjectSite site)
   at Microsoft.VisualStudio.Platform.WindowManagement.DocumentObjectSite.InitializeDocumentObject(Object punkView)
   at Microsoft.VisualStudio.Platform.WindowManagement.WindowFrame.InitializeDocumentSite(Boolean creatingStubFrame, Boolean replacingStubView, Object punkView, Object punkData, IServiceProvider pServiceProvider, IVsUIHierarchy pUIHierarchy, UInt32 vsid)
   at Microsoft.VisualStudio.Platform.WindowManagement.WindowManagerService.CreateContentPane(FrameMoniker frameMoniker, Boolean isDocument, String lpstrMkDoc, UInt32 eCreateWindowFlags, Object punkView, Object punkData, IServiceProvider pServiceProvider, IVsUIHierarchy pUIHierarchy, UInt32 vsid, Guid rguidCmdUI, ViewGroup parent, IVsWindowFrame& ppWindowFrame)

Solution is in: C:\Projects\syska\project

It's in a solutuin folder called: .rules ...

The file is located here: C:\Projects\syska\project\src\.editorconfig ...

vlade-rc commented 2 years ago

why this is closed without solution, I have the same issue with 17.0.4

syska commented 2 years ago

why this is closed without solution, I have the same issue with 17.0.4

I really have no idea ... it also fails on 17.0.5 ... so if any MS people are listening here. Please reach out if you need more information about the issue.

Eli-Black-Work commented 2 years ago

@jmarolf, Should this be reopened? Seems people are still having this issue (although it's been fixed for me 🙂).

Ridlsan commented 2 years ago

Same here, restart of vs helps....

jmarolf commented 2 years ago

Thanks folks, sorry that this is still happening. I did get another hit on this callstack that I am investigating. I am tracking that in a new issue here: https://github.com/dotnet/roslyn/issues/58732. If you have any more information to add please put it over there.

syska commented 2 years ago

Thanks folks, sorry that this is still happening. I did get another hit on this callstack that I am investigating. I am tracking that in a new issue here: #58732. If you have any more information to add please put it over there.

I can't really figure WHY ... because if I start moving the file around and add it again. Sometimes it starts to work.

So then I think it might be a User Context issue ... but having no knowledge of how VS works ... I not sure what to try. But better exception message about what exactly is missing or can't be found would be good.

I will update the other issues if I find anything new.

csharpforevermore commented 2 years ago

I get it as well (Visual Studio Community (64-bit v17.0.2) in a .NET Framework solution (MVC - v4.7.2). I left click the project so it is highlighted, right click the project, select "Add" > "New Item" and then I searched for EditorConfig. I get 2 options (.NET) and (default). I select .NET. The file name is ".editorconfig". When I click the "Add" button, I get a popup window titled "Microsoft Visual Studio" with a red cross on the left, and a message "Value cannot be null. Parameter name: path" with a single "OK" button.

This seems to occur anywhere I try to create a file of this type (any folder), and happens with both types of EditorConfig file (.NET and default).

Strangely, the file still gets created.

csharpforevermore commented 2 years ago

Also if i try to open the file, it throws the same exception. Here's the stacktrace message

error occurred while initializing the frame's content System.ArgumentNullException: Value cannot be null. Parameter name: path at System.IO.DirectoryInfo..ctor(String path) at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Extensions.SolutionExtensions.<>c.b__0_1(Project p) at System.Linq.Enumerable.WhereSelectEnumerableIterator '2.MoveNext() at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Extensions.SolutionExtensions.GetProjectsForPath(Solution solution, String givenPath) at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider.SettingsProviderBase'4.Update() at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider.Whitespace.CommonWhitespaceSettingsProviderFactory.GetForFile(String filePath) at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.DataProvider.CombinedOptionsProviderFactory`1.GetForFile(String filePath) at Microsoft.CodeAnalysis.Editor.EditorConfigSettings.SettingsAggregator.GetSettingsProvider[TData](String fileName)

File Path: .editorconfig Frame GUID: 68b46364-d378-42f2-9e72-37d8gc5f4468 Frame mode: VSFM_Float Error code: 0x80004003

jmarolf commented 2 years ago

Taking a look the fix for this is in 17.1 which has not been released yet. You can install the preview to get it early