Getting Error Message from Compiler

DrowningGeodude

New member
Joined
Feb 11, 2022
Messages
4
Programming Experience
Beginner
Hi, I am a beginner in C# and I am currently learning this program from an online PDF book.
Within the book there is a code example and the author stated that it should work if I put it in a C# compiler.

However, when I copy and paste the code into an online compiler I got this error message:
C#:
Unhandled Exception:
System.ArgumentNullException: Value cannot be null.
Parameter name: s
  at System.Double.Parse (System.String s) [0x00006] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
  at GlazerCalc.Main () [0x00007] in <31db6a95be144b39a4590ec15e205963>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentNullException: Value cannot be null.
Parameter name: s
  at System.Double.Parse (System.String s) [0x00006] in <12b418a7818c4ca0893feeaaf67f1e7f>:0
  at GlazerCalc.Main () [0x00007] in <31db6a95be144b39a4590ec15e205963>:0
This is the code from the book:
C#:
using System;
class GlazerCalc
{
static void Main()
{
double width, height, woodLength, glassArea;
string widthString, heightString;
widthString = Console.ReadLine();
width = double.Parse(widthString);
heightString = Console.ReadLine();
height = double.Parse(heightString);
woodLength = 2 * ( width + height ) * 3.25 ;
glassArea = 2 * ( width * height ) ;
Console.WriteLine ( "The length of the wood is " +
woodLength + " feet" ) ;
Console.WriteLine( "The area of the glass is " +
glassArea + " square metres" ) ;
}
}
 
Last edited by a moderator:
Make sure that there is no leftover running instance of your program. Then do a clean build. Then try running with the debugger in Visual Studio.
 
That looks rather like a run time error, not a compilation error. You're calling double.Parse in two places so obviously the executable is being run but no data is being received from a call to Console.ReadLine. If you run the executable yourself in the interactive console then you will input a value and it will work.

Why are you using an online compiler anyway? Can you not install VS Community, which is free? Even VS Code should do the job, with the .NET SDK installed to perform the compilation.
 
That looks rather like a run time error, not a compilation error. You're calling double.Parse in two places so obviously the executable is being run but no data is being received from a call to Console.ReadLine. If you run the executable yourself in the interactive console then you will input a value and it will work.

Why are you using an online compiler anyway? Can you not install VS Community, which is free? Even VS Code should do the job, with the .NET SDK installed to perform the compilation.
Thank you, the code is working in VS. I actually didn't know VS is called a compiler, when I googled search compilers for C# all they gave me are these online website compilers.
 
Thank you, the code is working in VS. I actually didn't know VS is called a compiler, when I googled search compilers for C# all they gave me are these online website compilers.
VS isn't a compiler. It's an Integrated Development Environment (IDE). That means that pretty much all the tools a developer needs are integrated into the one software environment. Prior to IDEs, developers would write their code in a text editor, compile it via the command line and then run it and attach it to a separate debugger. Some still do as they prefer to avoid any bloat but an IDE like VS - VS is pretty much the premier IDE but there are many others - makes life much easier. When you build your project or solution in VS, you are compiling your projects to executables, i.e. EXEs and/or DLLs. When you run a project, you are executing that output and, most likely, attaching a debugger.
 

Latest posts

Back
Top Bottom