CSharpAddImportCodeFixProvider encountered an error and has been disabled
Asked Answered
S

8

23

I had my PC re-imaged for me. I have Visual Studio Version 14.0.25123.00 Update 2 installed on my computer. I'm getting this error when I try to use VS intellisense to reference another project.

CSharpAddImportCodeFixProvider encountered an error and has been disabled

I have two projects. One of them using namespace ProjectName.Web. And the other project using ProjectName.Web.Controllers. The provider crashes when I reference ProjectName.Web.Controllers, I believe because it is setup as a project. Any idea how to fix this?

Saleem answered 27/4, 2016 at 20:5 Comment(4)
Same problem here... Any fixes / workarounds?Valueless
Update your Visual Studio. VS 2015 Update 3 is out nowSaleem
Have this error since Update 3 (no error before). Also have the new update 3 fix, no change. Still there.Peraea
Apparently this is not update specific bug and it is not mentioned in the release logs that it has been addressed. Try to Repair or uninstall/install again and see if that fixes itSaleem
S
5

I had the same issue on VS-2015 update 3.
I did was :

1) Closing visual studio

2) restarting as administrator

Sisterly answered 3/12, 2016 at 11:18 Comment(0)
S
2

Happened to me when chose Add using System.Data.SqlClient automatically after typing using (SqlConnection...){} in DataLayer, in one of Repository classes.

Nothing helped (except creating new project), but I saw that the problem was with loading System.Data.SqlClient.dll file, although it existed in appropriate folder.

Found by trial and error that after removing Dependencies->Assemblies->System.Data.SqlClient from DataLayer (right click -> Remove, or just press Delete key when selected), I can Add System.Data.SqlClient without any errors.

Didn't try for other cases where CSharpAddImportCodeFixProvider encountered an error and has been disabled message appears, but the solution might be similar.

In my case the problem appeared probably due to .net Core version conflict or something like that, because the project was on external drive and created on another computer.

Edit: Also, some errors might be caused by .vs folder (hidden by default) inside Solution folder, especially if the project is moved between different computers. I know from experience that IntelliSense can seem to be broken and classes from other namespace would be unavailable although using namespace_name statement is present. The solution is to delete .vs folder or just avoid copying it with the project, as suggested here: https://weblog.west-wind.com/posts/2018/Aug/07/Fixing-Visual-Studio-Intellisense-Errors

Scot answered 20/3, 2019 at 18:2 Comment(0)
B
1

There may be multiple reasons why this error occurs. So this answer may not apply to all situations, though it seems that it only occurs when another project is referenced.

The error does not occur for all statements. In my case I had the following code:

private System.Threading.Timer Timer;

public void Start()
{
    Timer.Change(0, 60000);
}

As soon as intellisense would open for Timer.Change( the error occurred. Please note that I had no parameters at that point. If valid parameters are present there will be no error.

I could solve the issue by updating the version of the framework. I found out that both projects targetted different frameworks, resp. 4.5.2 and 4.6.

As long as the framework versions are different the error occurs. As soon as both are equal (either 4.5.2 or 4.6) the error no longer shows.

I have tested this with VisualStudioVersion = 14.0.25420.1 (Visual Studio Community 2015).

-- update --

I've reported this as a bug to Microsoft. Including steps to reproduce.

Beatify answered 7/6, 2017 at 11:48 Comment(0)
G
1

I end up with this same error. what i did was to manually go and find the nuget packet for System.Data.SqlClient, installed and then invoke it in the class i was working on, like:

using System.Data.SqlClient;

Dont know if this is some kind of bug, cause it happens on a new blank project i create using visual studio 2019 community

hope it helps someone

Glaudia answered 4/2, 2020 at 21:50 Comment(1)
This fixed it for me on a .Net Standard library buildThrippence
O
1

Had the same problem solved by installing the sqlClient package from nuget package manager right-click on the project choose manage nuget packages.. and go to browse tab and search for System.Data.SqlClient and install it. that easy :)

Olwena answered 4/7, 2020 at 12:25 Comment(0)
G
0

Judging from the label you were given, "CSharpAddImportCodeFixProvider", I'd guess your problem was due to Visual Studio trying to identify and/or correct a missing "using" statement at the top of your C# source code file in which you made reference to a class that needed it. The Visual Studio components that usually deal with this type of problem are Intellisense, or third-party syntax highlighting/correction plugins like JetBrains' ReSharper.

On second thought, I'm not quite sure it's Intellisense's fault as opposed to the plugin ReSharper's. That's to be determined.

I did file a similar bug report with Microsoft. The error in my case seemed to be a result of the Intellisense not knowing how to deal with a logic error in my own code (see https://connect.microsoft.com/VisualStudio/feedback/details/3133049).

In my case, I had inadvertently placed code for a method outside its class definition, though inside its similarly named namespace. Visual Studio 2015 Update 3 complained,

'GenerateVariableCodeFixProvider' encountered an error and has been disabled.

The fix was to move my method back into its corresponding class definition, but it definitely brought a Visual Studio bug up to the surface.

Specifically, Visual Studio Intellisense had seen the line of code,

    Response.Write("I did something"); 

placed in a method that was declared outside a class definition (i.e., inside a namespace, but inadvertently not inside its class). The "'FeatureLabel' encountered an error and has been disabled" error was then displayed in a yellow bar across the top of my editor window and an "Enable" button and an "Enable and ignore future errors" button were displayed next to it.

I believe that Intellisense (or ReSharper?) tried to automatically deal with the situation and attempted to generate a variable for the keyword, "Response", but it tripped trying to do so--which in turn caused the error that was displayed.

Grevera answered 26/4, 2017 at 14:32 Comment(0)
W
0

anyone trying this solution from here ?

https://developercommunity.visualstudio.com/content/problem/623872/add-import-not-working.html

the last reply solves my issue..

Tools > Options > Text Editor > C# > Advanced

turning off Suggest usings for types in NuGet packages

Wasserman answered 23/10, 2019 at 4:12 Comment(0)
G
0

Visual Studio 2022:

I have solved it by installing package > Find and install latest version of missing DLL error.

First, click on error code > show potential fixes (Alt+Enter or Ctrl+.) > Install package.

See screenshot below:

enter image description here

Galligan answered 10/10, 2023 at 13:45 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.