can't launch debug window to check code - c#

I'm new to Visual Studio, I just started using it for my programming class. I downloaded C# 2010 from the website, and every time I try to debug the code the form window doesn't show up as the black box with the output, rather it displays a blank gray box. I have no clue how to check my code, I haven't been able to find anyone else with this problem, someone please help!

As you are assuming a black box - mean you want to start with a Console Application
and your are getting a gray box - mean you had chosen the Windows Form Application.
So What to do you is :
Select a Console Application.
Like File -> New -> Project -> Console Application.
Put breakpoints on your code. and press F5 to run your application in debug mode.

Put a debug point in the code on the left side where you have a empty column.. Then click F5 to run the code with debugging.. It will stop when the break point is hit..
Check this tutorial

Are you sure you have the solution configuration set to Debug ? Or is it Release? Read this for details.

Related

Visual Studio Break all then f11 not breaking next event

From this post I got this:
For debugging a button click without setting breakpoints:
Start the app with the debugger.
Get to the state immediately before the intended click.
Go back to the debugger and press Pause then F11 (Step Into) -- nothing will happen.
Go to the app and press the button -- the debugger should take over and drop you into the event handler.
This is Not Working for me however it was working for me Before. Dont know why its very awesome but not working now. Anyone?
Please reset your VS settings, and then debug it again.
I just use a simple Winform app in my side:
https://onedrive.live.com/embed?cid=55E83A59BF9AE3EB&resid=55E83A59BF9AE3EB%21893&authkey=AEmhE8zHWfnS4gE
It works well using the following steps:
(1)Debug the app(F5).
(2)Click "Ctrl+Alt+Break", I will get the result like the following screen shot.
(3)Click F11(Step Into).
(4)Click the button1, it will hit a breakpoint in the button1 click event, and then using F11 step into. The same steps as the button2 event.
I just use the default VS settings with the latest VS2015 Enterprise version 14.0.25431.01 update 3. So you could test it using the above simple sample, it still has this issue in your side, maybe we could think about the VS settings and the VS setup.

Line by line inspection of code in VS 2012

I have a C# WPF Application code, which I want to understand. I am using f11 and f10 to step-in and step-over. However, once my application begins, I don't know which part of the code is executing.
Here is what I want:
I want to know which part of the code is getting executed even after the application begins and as and when I click on menu in the application, I want to see which part of code is being executed.
Please I am new to c# VS 2012 and WPF. Help me in analyzing the application code.
You have a few options:
Click Pause when running, and then Step Into. This will bring you to the line being called when you click on a button or menu item for example.
Set a break point at the point you want it to break.
Inside your code, place Debugger.Break() to stop the debugger at a specific line of code.
here are some steps you can follow.
Start your debugging from f10 not from F5. this will start you
application under debug mode but from start evetn from main method.
while runing application under debug mode you can use pause button to
peek into where your code is running right now.
Use F11 when you wish to go in to the code(code need to be in your source tree.) to see what calling function is doing.
Use mode Debug while following these steps.

Debugging in monogame

How do you print or output text in Monogame?
I googled how to display text in monogame and was led to this:
Debug.WriteLine
Which says: "By default, the output is written to an instance of DefaultTraceListener."(and that page just confused me more).
So, if someone could direct me to a method of displaying DefaultTraceListener, or another method of outputting text in monogame, I would appreciate it.
I found it!
Using Debug.WriteLine writes to the debugger, which is in the output window in Visual Studio(by default at the bottom). It appears when you close the program(press F5 to start, Esc to close) by default in an OpenGL project.
If you like, you can use Console.WriteLine like you would in a normal C# console application, assuming you're developing a desktop application. There are a couple of steps.
Open the Properties for your MonoGame project
Select the Application tab
Change the Output Type to Console Application.
Your application should run as normal, only a console window should appear when you start the game.
Alternatively, you can use Debug.WriteLine, which will write to the output window in Visual Studio (it should appear when you start debugging your game).
If you use the standard Debug.WriteLine or Trace.WriteLine, then output goes to the default trace listener which can be viewed in the Visual Studio output window. Outside of Visual Studio, you can use programs such as DebugView (SysInternals) or LogFusion (Binary Fortress) to display the output. DebugView even has a feature for viewing debug output from a remote machine.
There are other trace listeners that can send output to a file, or to the Windows event log, or you can write your own trace listeners fairly easily.
You could also consider using a ready-made logging framework such as NLog, which would give you a great deal of flexibility. I have found in practice that using NLog turns out to be a lot easier than the built in stuff in .NET, because of the way it lets you easily reconfigure things and control/filter the output in a much more flexible way.
I know this has been answered, but if anyone else stumbles upon this, you can also use Console.Write(thing in here); or Console.WriteLine(thing in here); to write to the console window. WriteLine adds a line ending and Write does not.

Getting started with C#, how to Debug .NET 4.0 MVC3 Project?

I am trying to self teach myself C# and wondering if anyone can help me with what seems to be a basic C# question. I created a C# file with this code, started debugging but don’t see “Hello World” anywhere.
using System;
class Hello
{
static void Main() {
Console.WriteLine("hello, world");
}
}
http://msdn.microsoft.com/en-us/library/aa664628(v=vs.71).aspx
So I guess my question is this. Where should I expect to see “Hello World”? I have checked the Console and the Browser. Is there some setup that needs to be done to properly debug C# files. I am probably missing the big picture as to how C# works. I am use to PHP where I can just do something like this...
<?php
include 'my file';
echo 'my file included';
?>
Any help would be much appreciated. Thanks.
EDIT:
Thanks everybody for all of the help. You have all helped me understand and realize a number of things about C# / .NET. After extensive troubleshooting it is evident that the problem is not a mater of the debugging working, but the fact that my C# file doesn't appear to be properly hooked/included (not sure what its called in .NET terms) to the rest of the project. Anyways I am accepting keyboardP's answer as he answered first and technically gave me all the right answers. Also thanks to dasblinkenlight who was also extra helpful.
Additional Solution:
After insight from SO users. This article helped point me in the right direction.
http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/intro-to-aspnet-mvc-3
I'm guessing it's because the command prompt window is immediately closing. You can avoid this by adding Console.ReadLine(); after your WriteLine statement. This will wait for you to press return before closing the prompt window.
Alternatively, assuming you're using Visual Studio, you can run the build without a debugger attached by pressing CTRL + F5.
Edit - Based on the extra information added that you're using ASP.NET and not a console application.
Firstly, what are you trying to achieve? If you want to output debug information, then you can Debug.WriteLine instead of Console.WriteLine
System.Diagnostics.Debug.WriteLine("Hello World");
This will output the text to the "Output" window at the bottom of Visual Studio (by default).
Edit 2 Since you just want to write random text to the page, you can use
HttpContext.Current.Response.Write("Hello World");
There are sometimes issues with Response.Write but it should be okay for what you want to do here.
Use breakpoints. Set a breakpoint at the end of your method by clicking in the "gutter" area. A red circle will appear that looks like this:
Now run your program in debug mode by clicking the button with the green triangle or pressing F5. The program will run, producing the output in the console (a separate window). Once it hits your breakpoint, you can examine the console for the output, like this:
You are reading a tutorial for Console Application, however you are trying to create a ASP.NET application. I would reccomend reading a tutorial for ASP.NET
Like many before said: it goes by too fast, so either use breakpoints, or use a Read...
You can also write to your Visual Studio output window with System.Diagnostics.Debug.Write
you need to put break point over the line which you want to debug
short cut to placing break point is ctrl D,n
then you can step over or step into the code with f10 and f11 function keys

Open a Console/Command Window when using VS 2008 Express

I have both the VB and C# versions of Visual Studio 2008 Express. When I run a console application in either version, instead of the console opening in an old DOS style command window like it does in VS 2005, it actually blacks out both monitors attached to my computer and treats the entire screen real estate as the console.
Anyone know how to get the app to run in a small command-type window when I run it?
Update:
It's like the console is running Full Screen. If I set a break point, switch from the IDE t the console and then hit Alt+Enter it switches to the small window that I want, but I still can't figure out how to make the app start with the console that way.
I could post a screenshot but it would look like a big black square...no window, no frame, just the inky blackness of frustration.
Try this: Press your windows key + R to open a Run dialog. Type cmd and hit enter. This will open a command prompt. If it opens maximized, then un-maximize ("restore") it. Then close it. Now see if it starts maximized.
I think it's due to Windows saving the default size and placement of windows, and hopefully this will reset the default.
-Edit- Okay try this then: CMD Full Screen Visual Studio
Try pressing Alt+Enter to get out of full screen mode.

Categories

Resources