Visual Studio 2013 Breakpoint Issue with Razor - asp.net-mvc-4

For some reason, I can't set a breakpoint in #functions when using Visual Studio 2013. Here's an example:
However, the same kind of breakpoint works in Visual Studio 2012:
If you move the #functions block up to the top of the razor page in VS2013 you can set a breakpoint in #functions once again.
You cannot set a breakpoint in #functions if the block is somewhere in the HTML.
Anyone know why? Maybe a bug? This is a big inconvenience if you're migrating an web app from MVC4 or earlier where #function blocks appear in the HTML.

This seems like a known issue. See reported bug in MS Connect.
Description:
"After my upgrade to VS 2013, I am no longer able to debug javascript within MVC razor files. "
http://connect.microsoft.com/VisualStudio/feedback/details/807088/unable-to-debug-javascript-from-the-vs-2013-ide-unable-to-set-breakpoint

I had all of the same issues with "This not a valid location for a breakpoint", and I also had no code highlighting or intellisense on any of the Razor code. None of the solutions I could find resolved it. Primarily because my issue was due to a really dumb oversight on my part, but just in case anyone finds themselves here and have made the same mistake, I thought I'd share it.
If you did not physically create the view yourself in Visual Studio, like if it was created with a NuGet package (Umbraco in my case), or if you opened an existing solution that isn't yours...The view may not be included in the project. You may see something like this
Notice that the Homepage.cshtml file is in there and I can edit it, compile it, render it etc. But I could not insert a breakpoint anywhere. Right clicking on the file and Selecting "Include In Project" was the fix for me.

What worked for me was Excluding the file then Including it again. Picked up the Breakpoints straight away.
Hope it helps!

What helped me overcome this issue was enabling the "ASP.NET" option in the project-properties. See the screenshot:

Related

Visual Studio 2022: prevent collapsing folders in solution explorer (2)

This is a follow-up on the problem reported in this question with this same name.
I am having the same issue in Visual Studio 2022 of objects collapsing after a few seconds or when clicking on another object. The answer provided was changing a setting in CodeMaid, but I have not loaded CodeMaid and am having the same issue.
I have tried multiple variations of checking and unchecking Tools/Options/Projects and Solutions/General options "Track Active Item in Solution Explorer" and "Restore Solution Explorer project hierarchy state on solution load" and nothing works. As I code, I will open Controllers to see the list of methods inside or a data model to view the variables for reference while I am working on other aspects of the code. It is very frustrating to have them close after a few seconds, forcing me to reopen them again, over and over, throughout the day. Any help would be appreciated on this matter.
Update: A Microsoft Solution was posted here. They included a fix in Visual Studio version 17.3.5 supposedly. Update your IDE and the issue should hopefully be resolved.
This seems to be a known issue under investigation as reported in the bug tracker for Visual Studio. Using version 17.3.0 Preview 2.0 I too have observed this buggy behavior.
A few other users have mentioned on the same thread they are having the same problem. One user posted steps to reproduce which is similar to what I have tried to reproduce the issue myself:
I expand Blazor project, I expand Pages folder, I lookup and expand a particular .razor file which has a nested .razor.cs file with code, I expand it, see the class node, expand class node, click on a property and usually in this moment, after less than a second or so the branch collapses and the focus in on the razor.cs node.
The ticket says that it "worked-in:Visual Studio 2022 17.0" - perhaps try rolling back to this version if you can. Otherwise, you may have to wait for a fix.
I had the same problem and I think I found the cause and a solution. The problem is the preview tab, which opens automatically on the right side of the tab area when an element is selected in the solution explorer. I unchecked the Preview Tab option under Options->Environment->Tabs and Windows and haven't had any problems since.
greets...

InitializeComponent does not exist

InitializeComponent();
This code line appeared in all my Xaml pages' constructors in code behind.
It throws the following error:
InitializeComponent does not exist.
Now I cannot debug any page in my project although I have commented out this line.
How can I fix this?
Any help would be greatly appreciated.
Note: I'm using Xamarin Forms Portable project.
Update: When I comment out this line and run the pages, only an empty screen shows up in both IOS and Android although my pages were working correctly without error before.
Update 2: now the InitializeComponent lines are disappeared but the pages that I debug are still totally blank.
I have asked a question about this new problem on here.
I had also the same problem in Xamarin Forms Application.I fixed it by changing the Build Action to:
Embedded resource
for .xaml and .cs file both using property window.
Hope it may help you.
Change something in the page, then save it. Scarily this resolves the issue sometime.
If that doesn't work.
Update your nugget packages so Xam Forms is the latest.
"Clean" your project
Go to your project dir and delete the bin and obj from your projects via File Explorer.
Rebuild it.
Good luck.
Be sure that your Xaml page has property Custom Tool set to MSBuild:UpdateDesignTimeXaml
'Its not an issue. You can try to build your solution. Hopefully it will bulid perfectly. Most of the time I also get red under line on InitializeComponent(); like you same. Its a problem of Xamarin studio and Visual studio'
Is it the first XAML page you create in the project? or you created other pages and they don't contain this problem?
you can Check the comments here: http://forums.xamarin.com/discussion/17638/initializecomponent-does-not-exist/p4
Have you renamed your page? All XAML pages have a viewable partial class (the one you enter your logic code in to) and a hidden, system generated partial class.
If you renamed the class but did not use the VS rename macro, your system generated partial class no longer matches your editable partial class.
Try running 'Clean Solution' and 'Rebuild Solution' (both in the 'Build' menu) to see if VS can automatically detect and fix this for you.
If that doesn't work, make sure your pages are set as partial classes e.g. public partial class MyPage : Page
If you still have no luck, manually delete the 'obj' folder in your project's root folder, then rebuild again.
Simple trick:
Just edit your Xaml code..(Put space also enough..But need editing)
After edit the xaml page save project..
Now check error disappears..
In my case this was a result of intermediate build paths being too long for Windows. Moving my solution to just off the drive root C:\dev{solution} in my case solved the problem.
I had this problem because the namespace of my .xaml file did not match the namespace of the .xaml.cs file. Fixing the namespaces so they matched corrected the problem.

cshtml Razor Error messages, Conditional Formatting

I'm having a strange issue with my CSHTML files this morning. One moment everything is working fine... then next moment, everything is still working, but all my code highlighting for anything with # infront of it has gone.
The project still compiles and runs fine, but I'm getting red highlights where ever there is a
Code block.
There are loads of posts for Conditional Formatting on this site, but they all suggest changing the code. I don't want to change any code, it's all working fine. I just want to get the yellow colouring behind the # back.
It's all working fine in the aspx files. I can't think of what I did to turn this off.
Edit
I've created a new project and copied every code file over manually.
This is how it looks in the new project.
And like this in the old
That's a bug in Visual Studio. You can't do anything about it. It's just that the dudes at Microsoft didn't get Syntax Highligthing and Intellisense right in Razor views. Hopefully they will in some future version of Visual Studio.
There's nothing wrong with the code you have shown. It works perfectly fine at runtime. Just the tools you are using aren't capable of realizing that.

Changes in the code or the designer won't update when debugging

I am trying to debug my VB.net app in Visual Studio Express 2010, when I realized my changes will not update on my form-on the designer or in the code. After looking online, I found that you should clear out the "Debug" folder under the bin. That worked-for only one time. Now it went back to the older version and when I delete it again, it doesn't change. When I build the project and run it from the "Release" folder, it works perfectly, but when a error occurs at runtime, it won't show where the error is because it is running independently.
Thanks in advance.
(I have Windows XP SP3)
I had the same problem. Frustrating problem....? Close the project, go to debug bin/folder, delete these files, reopen project and rebuild it (F5).
- .exe
- .pdb
- .vshost.exe
- .vshost.exe.manifest
- .xml
it works 99.99%.......thanks
Before I'd create a new project, I'd copy all of the code-behind (including the code that creates the controls that you're not supposed to touch) into another form. That may be all you need to do. Try compiling that form and running it and see if it's good. If so, you won't have to create a whole new project and can just delete the old form.
I would think there's something causing this that would be much easier to to fix. Are there any config files or anything like that? Are you building to the right location?
It's been a while since I've done winforms, but I remember this happening in VS 2005 and I just created a new form and copied the code-behind into another winform and compiled.
Hope this helps.
mmm... if it was for me, with such a weird bug, i would create a new project then insert the files (not as a link, but a copy) in the project, and i most likely all will work fine after... Faster than finding where-the-hell is that wrong parameter...
So how do you do that ? Well create a new project, choose the folder and name, change namespace in settings if needed, then in project explorer Add existing item, then Browse and select your code and xaml (and other maybe) files. Let us know.
This happened to me as well. I believe the /bin and /obj folders of my application must've been locked for by some other application. Before manually deleting them I tried running Visual Studio as an administrator and did a Clean and a Rebuild which worked. If it doesn't work for you, try deleting the folders manually.
Close VS
Press Ctrl + Alt + Delete
Choose "Task Manager"
In the "Process" tab in "Task Manager" find your "ProjectName.EXE" and click "End Task"
Restart VS
I have the same problem, but i changed the solution config next to the start button from debug to release and that fixed my problem, try it :)
"Save all" works for me in VS 2010 VB, in Debug and Release mode.
I put the "Save all" icon next to the Run and Build icons.
First make sure your Localizable Property of you form is set to FALSE

Intellisense not working for XAML in VS2012 and only partially in Blend

I'm trying to get RC of Visual Studio 2012 working for XAML files. I can't seem to get any XAML Intellisense and the option within Tools is greyed out.
I've also tried to run the solution using Blend, however I only get Intellisense for custom controls such as telerik then.
When ever I drag controls onto the design surface I get an "Object reference not set to an instance of an object" exception but the control is still added to the surface.
I've read that this was a bug within VS11 and was fixed with in the Visual Studio 2012 RC.
I've created a new Silverlight Application and the intellisense is working so i'm wondering if its an issue with how my projects are set up.
I have all of my Styles within a separate themes project, which is referenced by other all other projects. Within the designer these references show up as errors but when the application runs they are resolved fine.
Would unresolved resources at design time affect Intellisense?
Click "Build -> Clean Solution", then "Build -> Build Solution". ("Rebuild Solution" alone doesn't work.) [Source]
If you have a reference to any of the expression blend dlls for interactions and you are using silverlight5 you will need to update the following dlls:
Microsoft.Expression.Controls.dll
Microsoft.Expression.Effects.dll
Microsoft.Expression.Interactions.dll
System.Windows.Interactivity.dll
Blend + SketchFlow Preview for Microsoft Visual Studio 2012
http://www.microsoft.com/en-us/download/details.aspx?id=30702
Ref Location:
C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\Silverlight\v5.0\Libraries
Exact same problem here, using WPF.
In my case, removing:
<Page.Resources>
<vm:AnyViewModel x:Key="anyViewModel" />
</Page.Resources>
Solve my problem...
One known cause of XAML Intellisense failure is if System.Windows.Controls.Toolkit is one of the project references. I've seen where deleting that reference instantly fixes the problem. The problem is described in the comments of this Connect bug for VS2012 Beta, but it applies to the RC with the July update as well.
I've found that some xaml designers for a control have this issue, where other controls are just fine.
The problem (in my case) seems to be if parameters are null or events call uninitialized singletons. Something the designer gives you a stack trace and other timers renders with no problem.
I've found by changing the back-end code for pages that don't have Intelli-sense to include DesignerProperties always fixes the issue (in my cases).
public Homing()
{
InitializeComponent();
if (DesignerProperties.GetIsInDesignMode(this))
return;
// some other code here that may have uninitialized members
}
t
I'm not sure if I had the same problem, but Intellisense mysteriously stopped working for me within a XAML file. I tried cleaning the build as someone suggested, but that didn't work.
After I restarted Visual Studio 2013, the Intellisense in the XAML page started to work again.