qinking126
qinking126

Reputation: 11915

visual studio 2015 debugger stop work, kept getting "error CS0103: The name does not exist in the current context "

I am using visual studio 2015 and created a blank mvc application using mvc core.

in startup.cs file, i added a new test method. then I just appended it to the hello world string. If I just run it, everything works. I got "Hello World! 3". but if I try to debug my code. I set a few breakpoints in the test method. when I move the mouse mover those a, b, c variables. I kept getting ": error CS0103: The name 'xxxx' does not exist in the current context". this is just happened today. and I created this brand new app, had nothing in there besides this simple method.

Here's what I did so far. restart visual studio, reset all settings. But still got the same error message. I think its the visual studio.

public class Startup
{
    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {

    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app)
    {
        int d = test();

        app.UseIISPlatformHandler();

        app.Run(async (context) =>
        {
            await context.Response.WriteAsync("Hello World!" + d.ToString());
        });
    }

    private int test()
    {
        var a = 1;
        var b = 2;

        var c = a + b;

        return c;
    }

    // Entry point for the application.
    public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}

Upvotes: 2

Views: 2122

Answers (1)

Will Ray
Will Ray

Reputation: 10889

I had a very similar siutation happen in my debugger with ASP.NET Core projects as well. I was able to correct it by going to Tools > Options > Debugging > General and checking "Use Managed Compatibility Mode"

enter image description here

Upvotes: 6

Related Questions