When attempting to run a C# console application without the debugger (ie Ctrl+F5) no output appears in the terminal.
When run with the debugger (ie just F5), program executes as expected.
I made a quick test project to make sure it wasn't just my project:
namespace Test
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Test");
Console.ReadKey();
}
}
}
Run with the debugger, "Test" is output to console, without it, nothing.
I don't know what I've changed, because (my original) programme was running fine without the debugger before now
Problem was found to be Avast preventing the executable from running properly. Temporarily disabling the File System Shield acts as a workaround.
Visual Studio 14.0.23107.0 D14REL
Avast 10.4.2233 (virus definition version: 151130-0)
Related
I just bought my first Windows today (I have always used mac), but C# in my visual studio will not work. Running this:
using System;
public class Class1
{
public static void Main()
{
Console.WriteLine("Hello World");
}
}
just gives me this error and does not print anything out:
CopyWin32Resources failed with exit App3 code 500
I'm getting very frustrated can someone tell me how to get passes this?
Please choose the Console Application template in the New Project Dialog in the category Templates \ Visual C# \ Windows and copy your source code into the main method.
Then your program should start and shows a console with "Hello world".
If you add the line Console.ReadKey(); then the console window will remain open until you press a key.
With a Windows Console Application you can see output to the Console.
I am developing an application that writes some exception messages to the Console if they are of no use to the user. As a result if someone runs the executable by simply double clicking it, they will never see these messages.
In Visual Studio these messages show up in the output window, but in my case I am testing my application on a machine that does not a Visual Studio installation, though I still want to see if any of these messages appear.
In the past I have simply ran the executable from the command prompt and it acted as the output window in Visual Studio. Though for some reason my application, when ran from the command prompt, simple "returns" and does not show any messages.
For example I might start it like so, and it instantly returns
D:\>MyApp.exe
D:\>
I am not sure if there is a specific switch I should use (I have tried /K to no avail) when I run it, or if there is something about my application that causes it to return.
Any ideas on how I might run it via the command line so I can see the messages?
For reference here is my applications Program.cs
static class Program
{
static Mutex mutex = new Mutex(true, "{12345678-1234-1234-1234-123456789012}");
[STAThread]
static void Main()
{
if (mutex.WaitOne(TimeSpan.Zero, true))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
SplashScreen.ShowSplashScreen();
Application.Run(MainForm.Instance);
mutex.ReleaseMutex();
}
else
NativeMethods.PostMessage((IntPtr)NativeMethods.HWND_BROADCAST, NativeMethods.WM_JTTMAINWINDOW, IntPtr.Zero, IntPtr.Zero);
}
}
To allow your program to output to the console, build it as a console application.
In Visual Studio, the relevant linker option is /SUBSYSTEM:Console ; or, when creating a new project, choose the "console application" template which will set the linker option automatically.
This will also mean that if you run the program from the command prompt, the command prompt will wait for the program to exit. Also, if you double-click the program rather than running it from the command prompt, a console window will automatically be created.
(There is no way to make the command prompt wait for a program but prevent the program from creating a console window if double-clicked. See this question and its answers for more information.)
Does any know how can I remote Debug Console application?
With snippet I can Hold the execution process util enter into the main code but, when I attach to the process from VS breakpoint appears not hittable.
static void Main(string[] args)
{
if (args.Any(arg => arg == "debug"))
{
while (!Debugger.IsAttached)
{
Thread.Sleep(10000);
}
Debugger.Break();
}
}
What you are showing is not how remote debugging works. You run an application on another machine (usually within your workgroup/domain) with the Remote Debugging tools installed on the REMOTE machine that match your version of Visual Studio. Make sure you deploy the application compiled as DEBUG and have the symbols available on the remote computer.
Then on your local machine, you need to go to the Debug Menu --> Attach to Process and connect the debugger to the running process that you want to debug on the remote computer. Now when the code is running and hits a breakpoint that you set locally (or exception), you'll see the debugger pause on your local computer.
MSDN: https://msdn.microsoft.com/en-us/library/vstudio/bt727f1t%28v=vs.110%29.aspx
EDIT - Locating Symbols File:
If you look in the location of your compiled binaries (bin folder then the compile type) and locate the file that ends in *.pdb. This contains the symbols. Make sure its in the same location as the exe on the remote computer
I am having issues with running a simple C# Console Application in Visual Studio 2013.
Details of my problem: I was running Console Applications successfully with the default "Press any key to continue" displaying cleanly at the end. Suddenly it started behaving differently with the following symptoms:
A new command window (cmd.exe) opening alongside my Console Application (this wasn't happening in the past)
My Console Application closing abruptly without the default clean "Press any key" message
cmd.exe hangs and I am unable to close it, even through the Task Manager -> End Process
My System Properties:
Visual Studio 2013 Ultimate
Windows 8, x64
This is my Console Application code just to show that it isn't a problem in my code:
class Program
{
static void Main(string[] args)
{
RegularTest();
}
private static void RegularTest()
{
Console.WriteLine("This is the Regular Test. It works!");
}
}
We had the exact same problem here during several weeks !
And we finally found a solution !
In our case, it was the anti-virus Avast which was corrupting the generated .exe !
The solution was to simply disable all agents while generating the release !
If you use another anti-virus, try to disable it.
I am trying to get crash dump debugging working with 2010, but it keeps failing.
I get this error when I try to start debugging:
"Managed Minidump Debugging: The signature verification for the file 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscordbi.dll' failed with the error 0x800700c1.:
I'm using the simplest program I can think of just to get off the ground (below).
Here are the steps I am taking:
Build
Run with a double-click from Windows explorer
right-click on the process in TaskManager, and select "Create Dump File"
kill the process
open the dump file in Visual Studio (File | Open, set filter to crash dumps)
Select "Debug with Mixed"
much loading of symbols (I have MS Symbol server enabled)
Boom (I get an error dialog saying I need to specify my symbol path -- which I believe I have done -- MS symbol server is enabled, and my solution is loaded)
In the output window, I get the following error (note that there are also a bunch of successful symbol loads, including for my exe):
Managed Minidump Debugging: The signature verification for the file 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\mscordbi.dll' failed with the error 0x800700c1.
(All the while, the solution with the code for my exe is loaded in the Visual Studio instance).
Any idea what I am doing wrong? Is this the right procedure for crashdump debugging in VS 2010?
The test dummy program:
class Program
{
public static string AStaticProperty = "Hello World";
static void Main(string[] args)
{
DoLoop(10000);
}
static void DoLoop(int iterations)
{
for (int i = 0; i < iterations; i--)
System.Threading.Thread.Sleep(500);
}
}
Edit
I'm going to vote to close -- I don't know exactly what the deal is, but everything is working now.
Here's what I did:
I started debugging the running process in VS 2010
I used the "save dump file" option off of the debug menu in 2010
I stopped the process and loaded the dump file.
It worked, so I thought "hmm, maybe the problem was with the dump file that I created (had used both adplus and TaskManager).
But no, now those work too. (although they failed very reliably until I did the 3 steps above). Weird, but now I cannot repro, so I'm going to vote to close.
Maybe this question/answers "Symbol issue when debugging C# code" helps you out.
The common tool used to debug dumps is WinDbg which is available in Debugging Tools for Windows. For x64 dumps you need the x64 debugger, while for x86 you need x86 debugger.
Visual Studio is x86 only, so you should not expect it can debug all dumps.
I think that this was an unstable machine/need a reboot issue. I have been unable to repro the problem