I've encountered a problem in expression evaluator of visual studio 2015 that says "Internal error in the expression evaluator", after some investigations I found that this is caused by an assembly that is loaded using reflection. This assembly wouldn't throw any exceptions but after that, vs exp evaluator will fail.
This is not the only assembly that I load, there are some good working ones that don't influent the evaluator.
To overcome this issue I had to check 'Menu > options > debugging > Use Managed Compatibility Mode' but this disables the 'Edit & Continue' feature, what can I do?
Properties of the causer assembly:
its name is the same as the main assembly
(i changed its name but nothing happened)
all of my projects are using dotNet 4.5
all root namespaces are same
(all of the assemblies are so)
Thanks!
That sounds like a bug in the expression evaluator. For a better workaround, instead of checking "Use Managed Compatibility Mode", check "Use the legacy C# and VB expression evaluators". This should enable you to continue using Edit and Continue as well as other features added within the last few releases.
In terms of the "Internal error in expression evaluator", can you please open an issue by going to Help -> Send Feedback -> Report a problem? That will help us fix the problem in future releases.
Just extending on the solution provided by Patrick Nelson. For Visual Studio 2015+ as inquired, the steps are as follows.
If you're debugging at the moment, this option will be unavailable. Stop the debugger.
Go to Tools -> Options
and here under the Options select Debug -> General and scroll down to find the ...legacy C# expression.. option:
More information is provided here:
Switching to Managed Compatibility Mode
Note: There are also some serious drawbacks that occur from switching to the legacy mode. Especially Runtime Reflection of the implemented Interfaces becomes almost an impossibility or extremely inconvenient. There are also other Reflection methods which will throw errors.
I finally figured out what created this problem in my Visual Studio!
The quick fix is to delete the debug object favorites from the "Documents/Visual Studio xx/Visualizers" folder and restart Visual Studio.
When you "pin" a variable in the debugger, Visual Studio saves a 'favorite' json object for it.
It appears that there is a bug in Visual Studio which corrupts the 'favorite' for some child variables that are dynamic in nature (not exactly sure of the conditions though).
For me checking "Use Managed Compatibility Mode" option worked. I was also seeing question marks when hovering over variables, instead of properties and values
I resolved this issue by simply resetting my visual studio settings by going to: to Tools->Import and Export Settings and selecting to reset to default settings
I had the same issue with VS2019. I ended up deleting my Documents/Visual Studio 2019 folder. Hope this might help someone, one day. Cost me a day.
PS. Probably not required to delete all, and of course not your projects (if they're in there), but in my case, everything in there was autogenerated by VS.
I of course tried all solutions mentioned here, and even reinstalling VS didn't work. Refactoring the class to another name was the 'trigger' which made me think there must be some cache, despite cleaning symbols and such didnt work.
In my case I was trying to evaluate lambda expression on List<> and had such error ("Internal error in the expression evaluator"). I was using VS2015, so lambda expressions were allowed. It turns out expression evaluator was lacking of Linq library. I added
using System.Linq;
to my current class and voilĂ ! Lambda evaluated.
I encountered the "internal error in the expression evaluator" error when I was debugging in release mode instead of in debug mode. I had changed it to Release when publishing to production and forgot to change it back to Debug.
Check your use of the [DebuggerBrowsable] attribute; I found a minimal case in VisualStudio 2017 15.5 and posted it here.
In this particular case, the expression evaluator (EE) crash appears related to the [DebuggerBrowsable] attribute applied to a property overriding a field of the same name. This will account for some percentage of the cases that people are experiencing out there, but there's no way of knowing how many are due to this specific issue until it gets fixed.
The full and complete demonstration example is shown in the image (and included below for good measure)
Machine-readable copy of the code in the image:
using System;
using System.Diagnostics;
class Program { static void Main() => new _derived(); }
abstract class _base
{
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
public Object trace;
};
class _derived : _base
{
public _derived() => Debugger.Break(); // <-- vs2017 EE crash when stopped here
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
new public Object trace => base.trace;
}
In my case, I had 2 same dll files in 2 different folders (seems, one dll was not correct). Deleting the .dll and rebuilding solution solved my issue.
In my case the data I was attempting to inspect was extremely large, a string which unexpectantly had hundreds of megabytes of data in it. The issue wasn't apparent when the amount of data being inspected was reasonable.
Related
I tried to include contracts into my project, something like:
public Segment Bounds() {
Contract.Ensures(segments.Length > 0, "Segments are not empty");
return new Segment(segments[0].a, segments.Last().b);
}
I get error (shown as message box) which said me that I should install CCRewrite. I got it
here, installed but "Contracts" tab in project settings was not appeared and I continue to get the same error. I'm using Visual Studio 2017 Community. Is it possible to use contracts with this version of Visual Studio?
From the CodeContract project wiki:
Visual Studio 2013 is the only version that is supported as a build environment for Code Contracts.
As pointed out in OP's comment, more background information can be found in the following issue:
I have the same issue, I bet on CC for some largish projects. As much as I love it and will miss it, I think everyone should seriously consider getting them out of their code base sooner rather than later. There is just not enough commitment there from either MS or the volunteers here (I don't blame them, it was always made clear that it's a non supported technology).
-- chrisaut
My conclusion (in accordance with #HansPassant's comment) is that the project is abandoned.
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?
I had the same issue on VS-2015 update 3.
I did was :
1) Closing visual studio
2) restarting as administrator
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
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.
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
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 :)
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.
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
How can we access the complete visual studio solution from code analyzer in Roslyn?
I have been trying semantic analysis without much help.
var sol = ((Microsoft.CodeAnalysis.Diagnostics.WorkspaceAnalyzerOptions)context.Options)
.Workspace.CurrentSolution;
This is what I came up with using intellisense but this always gives a null value.
In general, you can't. Analyzers run as part of commandline builds in csc and vbc, which have no notion of Workspaces or Solutions.
We are considering adding a VS specific analyzer API that would allow access to the Solution, but for Roslyn's 1.0 release, there is no supported way to do so.
For the moment WorkspaceAnalyzerOptions is internal sealed. One can use context.Options with reflection. Hacky, but working.
Solution solution =
((HostWorkspaceServices)context
.Options
.GetType()
.GetRuntimeProperty("Services")
.GetValue(context.Options))
.Workspace
.CurrentSolution;
Note, along with it the compiler gives a warning:
RS1022 Change diagnostic analyzer type to remove all direct accesses to type(s) 'Microsoft.CodeAnalysis.Host.HostWorkspaceServices, Microsoft.CodeAnalysis.Solution, Microsoft.CodeAnalysis.Workspace'
I am using Visual Studio online to manage my sources. I am also using Continous Integrations which means my source is compiled in the cloud on the TFS(Visual Studio Online).
I have my own build process template and also a few code activities. Since now everything works fine. After I edited the activities and also the template, everytime I start a build, I get the following error:
TF215097: An error occurred while initializing a build for build definition \BuildTest\BuildTasks:
Exception Message: Expression of type 'Microsoft.TeamFoundation.Build.Workflow.Activities.AgentReservationSpec' cannot be used for return type 'Microsoft.TeamFoundation.Build.Workflow.Activities.AgentReservationSpec' (type ArgumentException)
Exception Data Dictionary:
MS.TF.Diagnostics.Logged = True
A strange side effect is, that the order of the arguments of the build template in Visual Studio is now mingled and there are also some arguments, which are not defined in the template. This happens not only for my custom template, but also for the default templates from Microsoft.
Can anybody help me?
The cause of such errors is due to two versions of the assembly providing the erroneous type being visible simultaneously. The value being assigned from is from one and the value being assigned to is from the other.
This happened to me when I accidentally checked in a load of Microsoft.TeamFoundation assemblies into my custom activities location in source control. Removing these assemblies made the issue go away for me.
Also worth looking out for is if you have more than one version of the TFS API installed on your build controller (multiple versions of Visual Studio will do this). You may need to use explicit versions (full strong name syntax) in the references to TFS assemblies in your projects to ensure the correct API version is loaded.
I had the same problem with our local TFS instance. I removed all my DLLs from the CustomActivities-Folder in TFS and the error was gone.
Now second steop is to identify the CustomAction causing the problem ...
I am calling a static method on a class like
Foo.bar()
Visual studio's intellisense recognizes Foo and autocompletes bar for me (it highlights Foo and everything like it is working fine). Everything looks fine until I go to build the project, and it throws an error saying the name Foo doesn't exist in current context.
I am using this static method call in other files, so I know the class is ok. The situation is too big to post code, so I am mostly looking for reasons to start looking into that would cause intellisense to function normally but get errors on compile like this.
I've seen this error caused by differing versions of the .NET framework in the different projects. The Class Library I built was 4.5 and the application was 4.0, but the only error it gave was namespace errors. Changing the framework version on the class library and rebuilding it, then the application, resolved the error.
This can occur when namespaces, classes and variables become tangled when they have the same name. I have suffered with this before. Intellisense told me I was right, the compiler told me I was wrong! I trusted the compiler!
You have 2 options that I can think of
Search your code for Foo, and see it it is being used for something other than the static class.
Fully qualify the Foo.bar() call. MyApplication.This.That.Foo.bar();
Do it in that order...it's better to elegantly resolve the issue so you can just call Foo.bar() as this is more readable and maintainable than having MyApplication.This.That.Foo.bar(); all over the place!
In my case I was missing a } at the end of one of the methods in the middle of the code which was causing the program not see the rest of the code and complain about the Methods I have defined after that point.
Old thread I know, but I've encountered this issue when referencing a static method from within a unit test project - intellisense said the method was there, but when I tried to build/run the test (in Debug mode) I got the error 'name doesn't exist in current context'. In order to fix it I had to rebuild the project containing the referenced static method in Debug configuration (it had only previously been built in Release configuration) - after this the test built and ran OK.
I know this is a bit old topic, but I just experienced the same and for me it was because the file was not actually included in the solution.
I properly happened because I had renamed the class and then the file, which caused Visual Studio to still know the class and the namespace, but the compiler did not get the file as the renamed file was not included.
Consider doing a Clean and then a Build on the project with the problem. It is possible for the editor and Intellisense to correctly discover the class, while the compiler works with files that are out-of-date. (I had this same problem, and that's how I resolved it.)
this is an old article I know, but I just encountered this issue and has been puzzling me for couple of days, and eventually got to it: click on the class file, in Solution Explorer, then look at the Properties tab; make sure Build Action is set to "Compile".
Adjust the related file. If the error code in Default.aspx.cs, you need to change the top line in the file Default.aspx as below:
Replace "CodeFile=" with "CodeBehind"
Hope this can help.
-Thanks, Thai_FUV
I have run into this probelm a few times and so when I do, the first thing I check is if the assembly not recognized has any Nuget packages. In my cases they always have and I simply forgot to install the same packages in the assembly of which the reference to the un-recognized assembly is in. A re-build command and problem fixed. I hope this helps someone. This same error message can be given for multiple things so this particular case, may not apply. If you have not used Nuget than I would suggest trying the other answers
I also was running into this issue creating a data access layer and had static methods being called with the same symptoms: Intellisense finding it but not the compiler. I tried many of the above, including fixing the .Net version.
When adding the source files to the project I also changed the namespace.
With the file with the issue, I forgot to change the namespace to match when it was imported at another time.
Closing all tabs of MonoDevelop. Then Closing MonoDevelop. Finally opening MonoDevelop again solved the problem for me.
Mine was a little more convoluted solution. Project A referenced projects B and C: both references had Copy Local to true and both produced assemblies with identical names. When building the referencing project, the output assemblies from projects B and C were copied and one overwrote the other because they had the same name. VS was then looking for the references within the build directory and only found the assembly that had "won."
In my case I had to reload the project that was marked "missing".
Project > Unload Project
Project > Load Project
Clean, Build Solution
My solution to this problem that occurs every now and then:
Find the class that is giving you problems in the Solution Explorer and "Exclude From Project"
Rebuild that assembly (let's call it "A")
The project that used the file ("B") will ask you to "Reload" project, wait
Add the file back into assembly A, that you just removed it from, and rebuild
Now, reload project B
Then the file was found in VS and all was well.
Changing the id of the control resolved the issue for me. Apparently the id of the control existed in another part of the solution.
In my case, I was missing the following lines in my csproj file
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE</DefineConstants>
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
Once I added this, I could see the variables while debugging