C# in visual studio won't work - c#

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.

Related

Why is visual studio code printing C# to terminal correctly, but not output?

I'm new to C#. I installed Visual Studio code along with the NET framework, and when I run my project in the terminal via 'dotnet run', everything works perfectly.
Yet, when I switch over to the output window I see this message --
Can anyone lead me in the right direction? I've been going at it for 10 hours now - research, reinstalls, and restarts galore - yet nothing seems to help. Again I stress: in the visual studio terminal, the code works fine.
What gives?
Edit: I manually added scriptcs to path, and now the error has change - "You cannot declare namespace in script code"
using System;
namespace HelloWorld
{
class Hello
{
static void Main()
{
Console.WriteLine("Hello World!");
// Keep the console window open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}
This is what happens without namespace; still no output.
Turns out, I had to get rid of everything aside from:
Console.WriteLine("Hello World!");
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
I don't know why, but now 'run dotnet' in terminal doesn't work, yet the output does. Regardless, thanks to everyone who helpeD!!!

No output produced for C# Console Application on 'Start without Debugging'

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)

Console application not closing

I'm developing a console application that is supposed to run under WinCE 6.0 and WinCE 7.0. I'm using C#, Compact Framework 2.0 for different compatibility reasons.
My application is started by an external runtime called TwinCAT (from Beckhoff). Within this application, my teammate used a function block called nt_startProcess (documentation here) that is in charge of starting my application on demand.
My problem - Two different behaviors depending on the OS :
When started manually (without TwinCAT) from a cmd line :
My application behaves properly on both systems. It means that, the applications starts, displays "Hello World" and then returns to the cmd line.
When started from TwinCAT :
a) On WinCE 6.0, I can see a cmd line opening, displaying "Hello World" and shutting itself right after. Perfect behavior to me.
b) On WinCE 7.0, I can see a cmd line opening, displaying "Hello World" but it remains open forever. This is my problem!
Code snippet :
using System;
using System.Collections.Generic;
using System.Text;
namespace MyBasicExample
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World");
}
}
}
Compilation information
In Visual Studio 2008, within the Project compilation's properties :
Plateform target : Any CPU
Additionnal note :
Please note that the computer who is running WinCE 6.0 is using a i486 processor while the one running WinCE 7.0 is using a Freescale ArmCortex process.
WinCE 6.0 :
WinCE 7.0 :
What I tried :
1) Using return 0; at the end of application.
Doesn't change anything on WinCE 7.0.
2) Using Environment.Exit(0);
Is not available in Compact Framework 2.0.
3) Using the property : IsBackground
Snippet :
// ... Same snippet as above except for the next line...
Thread.CurrentThread.IsBackground = true;
Console.WriteLine("Hello World");
// ...
4) From TwinCAT, calling a batch file (which calls my exe) instead of my exe.
Doesn't work with TwinCAT. I get an error of type "General Sub-Windows error".
5) Tested with the Compact Framework 3.5.
Same behavior.
6) Tested with another CX computer (model 2020) using Windows CE 7.0 and another processor architecture (Intel Pentium III Xeon Model A).
Same behavior.
try this code:
Environment.Exit(0);
Try this:
Tools > Options > Debugging > Automatically Close the Console When Debugging Stops
Are you putting you .exe file in Arguments property of ProcessStartInfo ?
If you must do that, I believe that you're using CMD in FileName property, so you must use /K before your .exe name.
Or just put in FileName the .exe path.
You can clarify a lot if you put the code that calls your application.
Try calling Application.Exit
This works in windowed applications, and may force the console window to close.
I had exactly the same problem. Running console app on Beckhoff PLC which never closed.
Instead of creating Console app I created Windows App.
My code stayed the same as for console app. I just commented out:
// Application.Run(new Form1());
Seems now codes run without opening a form.

Writing to standard output from c# program

I have the following C# code
class Test
{
public static void Main(String[] argv)
{
Console.WriteLine("Hello ");
}
}
When I run the program from the command prompt, I do not see output. The c# file name is file.cs and compiles into file.exe.
When I run this from the command prompt:
c:\>file.exe
I do not see any output. But it works if I run this:
c:\>file.exe | more
I understand I need to do something other that console.WriteLine(). Is there any way that I can redirect all Console.WriteLine() calls to standard output?
Application type was set to Windows application in Visual Studio project properties.
I set the application type to "Console". This fixed the issue. Now all Console.WriteLine statements gets printed to command window.

C# Console Application - cmd.exe hangs

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.

Categories