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.12k stars 4.04k forks source link

Add Import not working #39531

Closed vsfeedback closed 4 years ago

vsfeedback commented 5 years ago

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


After updating to 16.2.0 preview 3 the import namespaces feature (when you do Ctrl + . ) stopped working

System.NullReferenceException : Object reference not set to an instance of an object. at Microsoft.VisualStudio.LanguageServices.Packaging.PackageInstallerService.GetPackageSources() at async Microsoft.CodeAnalysis.AddImport.AbstractAddImportCodeFixProvider.RegisterCodeFixesAsync(<Unknown Parameters>) at async Microsoft.CodeAnalysis.CodeFixes.CodeFixService.GetCodeFixesAsync(<Unknown Parameters>) at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>) at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)


Original Comments

Visual Studio Feedback System on 6/27/2019, 01:59 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.

Visual Studio Feedback System on 6/27/2019, 10:19 AM:

This issue is currently being investigated. Our team will get back to you if either more information is needed, a workaround is available, or the issue is resolved.

Joey Robichaud [MSFT] on 6/27/2019, 00:50 PM:

@yfernandes Sorry that we broke you. We introduced a bug in Preview 3 when querying NuGet packages that has already been resolved for the final release.

Can you find the Using Directives group in Tools > Options > Text Editor > C# > Advanced and try turning off `Suggest usings for types in NuGet packages`?

Please let me know if you still have any more trouble.

-Joey

sean on 10/24/2019, 07:30 PM:

@Joey Robichaud [MSFT] This appears to still be broken in 16.3.6, however the solution of disabling "Suggest usings for types in NuGet packages" did solve the problem for me.

This bug is brutal, because the cause (and solution) isn't obvious and importing usings is such a common practice, not having it kills productivity.

Joey Robichaud [MSFT] on 10/25/2019, 02:16 PM:

@sean I was wondering if you could help me with some steps to reproduce your issue?

I expected a minimal repro with 16.3.5 to be:

  1. Create new Console app project
  2. Inside the Main method type JsonConvert
  3. Press ctrl+. to bring up quick fixes

Expected Outcome:
Suggestion to import Newtonsoft.Json

Actual Outcome:
Gold bar warning that CSharpAddImportCodeFixProvider had encountered an error.

However I am not getting an error locally.

-Joey

sean on 10/25/2019, 02:53 PM:

Joey,

I'm not sure how to reproduce the issue - however I'm on 16.3.6.

The issue I originally reported was closed and my voted was merged into this one.
In my original issue I reported my VS version was 16.3.6 and the issue appeared after upgrade from 16.3.5.


Original Solutions

(no solutions)

GeertVL-zz commented 5 years ago

I got the same issue after installing 16.3.6 and by creating a simple new class library. Even the nuget package manager cannot open anymore.

br3nt commented 5 years ago

I just followed the instructions:

Can you find the Using Directives group in Tools > Options > Text Editor > C# > Advanced and try turning off Suggest usings for types in NuGet packages?

I can confirm that after deselecting Suggest usings for types in NuGet packages and then resarting VS, the using <package> option was again appearing in the suggestion context menu and the exception was no longer being raised.

br3nt commented 5 years ago

A followup to my last comment....

I just noticed that when unchecking Suggest usings for types in NuGet packages, it also removes the Manage NuGet Packages... option when right clicking on the project's Dependencies folder.

I also now have issues with the Package Manager Console where it is getting stuck on Initializing PowerShell host... which I wasn't experiencing before.

Checking Suggest usings for types in NuGet packages brings back the Manage NuGet Packages... option, but I'm still stuck with the Initializing PowerShell host... bug.

br3nt commented 5 years ago

Is this bug mentioned by the OP some how related to or have a connection with the bug mentioned here??

daveaglick commented 5 years ago

I was having the same problem - the CSharpAddImportCodeFixProvider kept crashing and I wasn't getting "add using" code fixes. Turning off "Suggest usings for types in NuGet packages" resolved the issue for me.

pranavbhagwat81 commented 4 years ago

I have tried Turning off "Suggest usings for types in NuGet packages". still I have the same issue.