In the output window, there are sections called Build, Debug, and Refactor.
When I do Trace.Write("Hello World!");, it goes to the Debug section.
Can I create my own section like that and print data to it? I know there is a way to write a file but I just need to see the output temporarily in Visual Stutio.
I'm not sure if my question is clear or not, but is this possible?
Only Visual Studio addins can create new output sources (those inside the output tool-window), like AnkhSVN does, and many others may also do.
I don't think you can do that from the code being debugged.
You can however try to create a custom listener and add it to Debug.Listeners.
You can make your own output form, with a text-box on it, and make a listener that outputs to that window, or something similar.
Related
I am getting this conflict every now and then, the spaces(....) are shown as a tab(->) when I am changing something in code. I am attaching an image, where I compared my file with the previous one. If anyone encountered with same error please let me know.
Conflict Image:
You can either change to an external comparer, one that can be configured or setup the code formatting in visual studio to adhere to the project formating guidelines whatever they are.
To configure the Visual Studio, just go Tools --> Options --> Text editor --> All languages (or the one you are using) --> Tabs and change the settings to whatever behaviour works for you.
You seem to have the editor tool configured the use tabs instead of spaces.
How you can control this in VS is answered by https://stackoverflow.com/a/51922994/3906760.
There is, however, another way how this could be controled from "the outside". There is editorconfig (you can spot this, if there is an .editorconfig file your repository), then on save the files will be converted automatically. This is also a way, to consistently push the coding rules to other developers.
Hello guys I have a easy problem but I can't solve.
I open normal project and add something when I try to close without debugging client asks "Do you want to save" but when I use debug then I try to close project client don't ask "do you want to save" just saves automaticially I want to change this options i change a lot setting (tools>options) but I couldn't do it.this situation makes me crazy can you help ?
When you start debugging, it compiles the source code. In order to compile, it has to access the latest version of the files, so it has to save them, else the compiler (another program than Visual Studio) can't access them.
Conclusion: there is no way to change this unless you can change the entire working of Visual Studio and the compiler.
Sounds like you need to look into one of the Source Control options that will allow you to revert to older code if needed.
I use breakpoints in debugging my C#/.Net programs. Very often I use many "When hit" breakpoints to display messages in the Output window and keep going, so I can examine what the program is doing while it's executing.
But I often find that after editing code my breakpoints get moved, producing spurious or incorrect results and I have to go and delete my old breakpoints and make new ones.
Searching for this on Stack Overflow I find other programmers having this problem when building in Release mode, but I'm building with a Debug configuration.
How do I make my breakpoints stay put?
Do you "share" files such as .csproj.user, .suo... with other developers of the project ?
If you are using a SCM exclude them from it, these files are not intended to be shared between different machines. To send them to another user with slightly different sources may cause this kind of funny mess.
More details about these files here :
Best practices for Subversion and Visual Studio projects
This kind of thing could also happen if you manually edit files, outside of VS (with Notepad++ for example) : try to avoid this when you want to keep breakpoints at the right place, VS doesn't like it at all.
There are many ways to examine the execution of program. Make sure you are generating full Debug Info for your project. Also check that csproj.user, .suo files aren't set as Read Only.
If these thing doesn't work, for your case I suggest you to use some console based output providing methods.
Try this one
Console.WriteLine("Currently executing this...");
The console here is the output window of VS. Select Debug from 'Show output from:'.
If you want to halt the execution, use this code
Console.WriteLine("Currently executing this...");
System.Diagnostics.Debugger.Break();
You should do conditional compilation of your code so that this doesn't get released with the final product. Console.WriteLine() will not cause any problem but System.Diagnostics.Debugger.Break() will break application.
I have a C# solution which contains a project and a class library written by somebody else. The class library gets GPS data via wifi. The project shows the processed data on a map. Now, I want to see the contents of some variables in the class library in real time for the sake of debugging.
I tried to use
System.Diagnostics.Debug.Write(value)
without success. It seems it does not do anything.
Also I tried "MessageBox.Show(value.ToString())" which was good but it stopped the wifi reading and interrupted the program as I needed to press OK button each time that it showed up.
Moreover, I added a windows form (which contained a textBox) to the class library to print the data in the textBox, however, when I wrote:
Form1.textBox1.Text = value.ToString()
It gives me this error:
Error 3 'MapNMEA.Form1.textBox1' is inaccessible due to its protection level C:\Users\john\Documents\Visual Studio 2010\Projects\new ver of map purecom\MapExplorer\MapExplorer\MapNMEA\MapNMEA\SerialPort.cs 184 27 MapNMEA
"MapNMEA" is the name of the class library. Also "MapExplorer" is the name of both solution and the project. "SerialPort.cs" is a file inside the class library in which I wrote the above code.
My question is how to show the content of those variable (they are 3,4 variables) in real time and this act should not stop the wifi reading. I need to do this as an electrician who does not know much about programming wants to check whether a GPS device sends the data to my computer correctly or not.
UPDATE 1: Actually I noticed that System.Diagnostics.Debug.Write(value) is working but as there was too many warning messages showing up in the debug window, I did not noticed it. Now, if somehow I could remove (or hide) other (warning) messages, I would see only my desired output. Do you know?
Debug.Write should be fine if you attach a listener first (Debug.Listeners.Add( new _a_listener_type() )).
Also, you should probably be aware of the AutoFlush property on the Debug class which determines whether or not Flush is automatically called.
Debug.Write should work - by default it will write to the 'Debug' window in Visual Studio if you have the debugger attached. Are you sure you're looking in the right place?
If you want to use the form approach, you need to keep track of the instance of the form which is open, and give it a public method. For example:
public void WriteDebug(string message) {
TextBox1.Text += message + Environment.NewLine;
}
Then you can call formInstance.WriteDebug(message);.
Do you run debug build? Also your code with textbox does not work, because textBox1 is non-public
I think you may not be searching the right location: Is there something preventing you from debugging on a PC first before going to a target? If not, the you should probably use the traditional way: put spies on variables, use your IDE (Visual Studio) to watch them and so on.
If you actually NEED to run on target without advanced debug tools, then you might want to take a look at some easier solutions:
log them to a text file (append or replace, whatever you need), then have a viewer opened at hand
make another non-modal form with a textbox, and call a form2.writeDbgTextBox(String) every time you need to refresh
Be sure to remove this code on release (eg. by putting them in a #if DEBUG section)
And whatever happens, DO NOT try to write to an existing Message box! they are made to pop up and close, not to interact with your code.
Trying to debug a controllers action method, and when I attach to process the debug icon goes hollow and says the 'current breakpoint will not be hit'
But I am doing a response.write at that point and when the page renders it does output the test text.
So that section is indeed being executed, why does debug mode not work?
Your source code may be different than the version of the corresponding process that you are attaching to. Your other process may also be built in release mode, i.e., there is no debug info.
There are a few reasons why you may see this message:
You are attached to the wrong process
You are attached to the right process but the AppDomain hasn't loaded the assembly yet
You are attached to the right process but you have forgotten to build so the source code and the PDB file are out of sync
I've noticed this happen when using reflection and dynamically loading .dll projects. If the code isn't specifically reference (i.e. you are using interface animal but dynamically loading implementations of animal such as cat/dog) it will say it won't hit the breakpoint, but actually does.
I do not like to play with knives but the only thing that worked for me involves editing the .csproj file itself. So, unload the project file, edit it by cutting and pasting the three asp.net files so that they are together in the ItemGroup. However, sometimes it is necessary to go further as explained here: http://carnotaurus.tumblr.com/post/4130422114/visual-studio-debugging-issue-with-files-of-the-same - Also, I give a list of other proposed solutions that did not work for me. I hope it helps.
Another reason is when you attach to the process to quickly.
For example, when I attach to Excel to debug a VSTO add-in (I am using Add-In Express), if I Build, then Start > Run > Excel, then quickly press Ctrl+Alt+P to attach to process, then press E to highlight Excel and press Enter I see this, before Excel has loaded:
The result is no Breakpoints will be hit.
However, if I give Excel a couple of seconds to load and then press Ctrl+Alt+P, notice the Title is showing:
The result is Breakpoints will be hit.
It also tells me your source code is different from the version but it is not true. I build the whole solution, then attach to process, but still it says the breakpoints won't be hit because the source code is different. Maybe it is a bug?