Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This is not a valid location for a breakpoint

I am trying to put a breakpoint on below mentioned page in my ASP.Net MVC 2 application's .ascx or .aspx files in Visual Studio 2010. But it won't let me, it shows:

"This is not a valid location for a breakpoint".

Earlier it did work. Why is that? Any help is appreciated.

My .ascx page looks like this:

enter image description here

EDIT 1

.cs files it's working.Not working only on .aspx and .ascx files

EDIT 2

None of the below mentioned links of comment section are giving a solution for the issue.B'cos we cannot add additional code for the code base only for debug.So is there any method to just activate the red mark(debug mark) for my view's c# codes like mentioned on image?

EDIT 3

It's working for inside the javascript tags on same file but not for the c# code.Any Clue ?

enter image description here

EDIT 4

Above mentioned issue came after I installed Windows Azure SDK for .NET - October 2012

When I compile the code it gives Waring message like below.

enter image description here

like image 929
Sampath Avatar asked Dec 20 '12 08:12

Sampath


4 Answers

This problem will happen if you are using Asp.Net Mvc 5 in Visual Studio 2012, but have not installed the proper tooling. For me, this happened because I upgraded my version of Asp.Net Mvc 4 to version 5 via Nuget. However, this did not install the tooling in VS 2012 so that the IDE can properly parse and handle the .cshtml files. Thus none of the razor code showed up as valid C#, and it was impossible to set any breakpoints (with the error "this is not a valid location for a breakpoint" if you try to set it).

The solution is to install the proper tooling. (or direct link) Once I installed the tooling and restarted VS, I was able to happily set breakpoints in .cshtml files once more.

like image 176
Kirk Woll Avatar answered Sep 25 '22 20:09

Kirk Woll


Looking at the content of the <% %> code block in your screenshot shows that the syntax is not highlighted. Usually this means that VS has not recognised that the block contains server side C# code.

It works for Javascript because VS can recognise that as client side script and break on it.

Fix the syntax highlighting and you'll be able to break on it too.

Typically this happens because VS has a tough job switching between HTML editing (with visual preview, of a sort) and C# code and occasionally gets it wrong.

The commonest cause of this is a missing Language directive at the top of the .aspx or .ascx file:

<%@ Page Language="C#" ...

Or

<%@ Control Language="C#" ...

You can also try an explicit code block, something like:

<script type="text/C#" runat="server"> ...

This can also be caused by nested .master pages: try clearing the ReflectedSchemas folder: %appdata%\Microsoft\VisualStudio\10.0\ReflectedSchemas\

Removing the ReSharper trial has also been known to cause this.

Finally, sometimes it's just confusion on VS's part - try restarting, and if that doesn't work try reorganising the file and restarting again. Stupid (I know) but sometimes that prompts VS to figure it out.

Incidentally this is something they've significantly improved in VS 2012

like image 42
Keith Avatar answered Sep 25 '22 20:09

Keith


After showed the syntax highlighting issue by @Keith I went through my file top to bottom and vice-verse. Then I have found the issue.

There was a warning message on my project as I showed on EDIT 4 above.

After I solved that issue, Brake point (debug) issue also vanished.

For that I have used below mentioned Link.

Could not load file or assembly 'msshrtmi' - incorrect format in Azure deployment

In future I will write a complete step by step guide to show how to get rid-off this issue.

Thanks for every one who gave me a support.

like image 1
Sampath Avatar answered Sep 26 '22 20:09

Sampath


This is a bug in Visual Studio 2013. It should be fixed in update 2 (or higher).
That said, updating only temporarily solved the problem for myself.

like image 1
Protector one Avatar answered Sep 26 '22 20:09

Protector one