why System.ArgumentNullException'

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • davesNotHere

    why System.ArgumentNullException'

    Greetings, experts!

    I'm having a bit of a problem importing some working code from last
    night into Visual Studio. The code compiles correctly, but when I run
    the program, it doesn't seem to open the text window to ask for input.
    It simply errors on the ReadLine statement. (See the attached code.)

    When I use "Start Without Debugging", I received an exception window
    that says "An exception 'System.Argumen tNullException' has occurred in
    CSharp2.exe". It then gives me the option to debug. ("Do you want to
    debug using the selected debugger?") When I press the "Yes" button, the
    program shows the error on the line "double radius = double.Parse
    (Console.ReadLi ne());"

    I speculate that this is some configuration problem with my local
    environment, but (after much searching) I can't find any.

    Do you have any ideas on this one?

    Thank you!

    Dave

    here's the source-code:

    using System;

    namespace CSharp2 {
    public class GetArea {
    static void Main(string[] args) {
    Console.Write(" Radius: ");
    double radius = double.Parse(Co nsole.ReadLine( ));
    while (radius != 0) {
    double area = radius * Math.PI;
    Console.WriteLi ne("With radius = " + radius + ", Area =
    " + area);
    Console.Write(" Radius: ");
    radius = double.Parse(Co nsole.ReadLine( ));
    } // while (radius != 0)
    } // static void Main
    } // public class GetArea
    } //namespace CSharp2

  • Andrew Kirillov

    #2
    Re: why System.Argument NullException'

    Hello



    If you are trying to import some code from the last NIGHT, then may be you
    just missed the "Output Type" property of your project ? Try to check that
    it is set to "Console Application". Because the described error is a symptom
    of "Window Application" set in output type.




    --
    With best regards,
    Andrew




    "davesNotHe re" <me@here.org> wrote in message
    news:MPG.1d809e 58e9de2e9c98968 f@news.verizon. net...[color=blue]
    > Greetings, experts!
    >
    > I'm having a bit of a problem importing some working code from last
    > night into Visual Studio. The code compiles correctly, but when I run
    > the program, it doesn't seem to open the text window to ask for input.
    > It simply errors on the ReadLine statement. (See the attached code.)
    >
    > When I use "Start Without Debugging", I received an exception window
    > that says "An exception 'System.Argumen tNullException' has occurred in
    > CSharp2.exe". It then gives me the option to debug. ("Do you want to
    > debug using the selected debugger?") When I press the "Yes" button, the
    > program shows the error on the line "double radius = double.Parse
    > (Console.ReadLi ne());"
    >
    > I speculate that this is some configuration problem with my local
    > environment, but (after much searching) I can't find any.
    >
    > Do you have any ideas on this one?
    >
    > Thank you!
    >
    > Dave
    >
    > here's the source-code:
    >
    > using System;
    >
    > namespace CSharp2 {
    > public class GetArea {
    > static void Main(string[] args) {
    > Console.Write(" Radius: ");
    > double radius = double.Parse(Co nsole.ReadLine( ));
    > while (radius != 0) {
    > double area = radius * Math.PI;
    > Console.WriteLi ne("With radius = " + radius + ", Area =
    > " + area);
    > Console.Write(" Radius: ");
    > radius = double.Parse(Co nsole.ReadLine( ));
    > } // while (radius != 0)
    > } // static void Main
    > } // public class GetArea
    > } //namespace CSharp2
    >[/color]


    Comment

    • Raj Chudasama

      #3
      Re: why System.Argument NullException'

      i am not sur if the problem is the output type. I think you are getting a
      null value from the console.

      try using

      string s = Console.ReadLin e();

      if(s.TrimEnd(nu ll) && s.Length > 0)
      try
      {
      Double p = double.Parse(s) ;
      }
      catch(Exception e)
      {

      }


      "davesNotHe re" <me@here.org> wrote in message
      news:MPG.1d809e 58e9de2e9c98968 f@news.verizon. net...[color=blue]
      > Greetings, experts!
      >
      > I'm having a bit of a problem importing some working code from last
      > night into Visual Studio. The code compiles correctly, but when I run
      > the program, it doesn't seem to open the text window to ask for input.
      > It simply errors on the ReadLine statement. (See the attached code.)
      >
      > When I use "Start Without Debugging", I received an exception window
      > that says "An exception 'System.Argumen tNullException' has occurred in
      > CSharp2.exe". It then gives me the option to debug. ("Do you want to
      > debug using the selected debugger?") When I press the "Yes" button, the
      > program shows the error on the line "double radius = double.Parse
      > (Console.ReadLi ne());"
      >
      > I speculate that this is some configuration problem with my local
      > environment, but (after much searching) I can't find any.
      >
      > Do you have any ideas on this one?
      >
      > Thank you!
      >
      > Dave
      >
      > here's the source-code:
      >
      > using System;
      >
      > namespace CSharp2 {
      > public class GetArea {
      > static void Main(string[] args) {
      > Console.Write(" Radius: ");
      > double radius = double.Parse(Co nsole.ReadLine( ));
      > while (radius != 0) {
      > double area = radius * Math.PI;
      > Console.WriteLi ne("With radius = " + radius + ", Area =
      > " + area);
      > Console.Write(" Radius: ");
      > radius = double.Parse(Co nsole.ReadLine( ));
      > } // while (radius != 0)
      > } // static void Main
      > } // public class GetArea
      > } //namespace CSharp2
      >[/color]


      Comment

      • davesNotHere

        #4
        Re: why System.Argument NullException'

        In article <#n#NoovrFHA.90 4@tk2msftngp13. phx.gbl>,
        andrew.kirillov @gmail.com says...[color=blue]
        > Hello
        >
        > If you are trying to import some code from the last NIGHT, then may be you
        > just missed the "Output Type" property of your project ? Try to check that
        > it is set to "Console Application". Because the described error is a symptom
        > of "Window Application" set in output type.
        >[/color]

        Thank you, my friend. That did it.

        Best Regards,
        Dave

        Comment

        Working...