bug in Int32.Parse

In Visual Studio 2005, the following throws a FormatException and it definitely shouldn't.  The same code works fine in Visual Studio 2003.

This is the version that I am seeing the problem, running on XP:
    Microsoft Visual Studio 2005
    Version 8.0.50727.42  (RTM.050727-4200)
    Microsoft .NET Framework
    Version 2.0.50727
    Installed Edition: Professional


int x = 0;

x = Int32.Parse("0")        // throws FormatException
x = Int32.Parse("00")       // works fine
x = Int32.Parse("000")       // works fine
x = Int32.Parse("0000")       // works fine





Answer this question

bug in Int32.Parse

  • fahadmoon

    Is there a colleague machine where you can install the same ISO, preferably a clean machine (maybe you can bother the receptionist! :) ), type up the test case from scratch, and see if it reproduces the problem

    Brian


  • MarceloRamos

    It's definitely a zero.

  • David Wang

    also fine in C# Express 05

  • CraigZ

    Brian, please give this a try when you get the RTM version.  And let me know your results.

    Thanks,
    Kevin

    By the way, another problem that must be related to this also pops up when you try and modify the Assembly Information through the new graphical UI in the IDE.  If you try and modify the Assembly Version and put zeroes in for any of the values (major, minor, revision, build), a dialog pops up saying:

    Each part of the version number for 'Assembly Version' must be an integer between 0 and 65534.

    It also happens for File Version on the same dialog.

    If the values are already zeroes when populating the dialog, hitting OK won't exhibit the problem, you have to change one of the values first.



  • BrunoRdaSilva

    I'm not getting this problem either - and I have the same version  as you.

    You didn't by any chance have an earlier beta on the same PC, did you

    There's definitely something weird going on there!

  • RMJR

    I got a FormatException when I replace 0 (zero) with O (the letter after N).  But that looks like an 0 up there...

    Brian

  • Klaus65

    http://msdn.microsoft.com/feedback is where I go for my daily wheel-squeaking needs. 

    This probably got past their QA because it's working fine against their tests (along with the two people in this thread who couldn't repro it either.)  I suspect a bug report might easily get dismissed as no-repro based on the information you are able to give them.  Hopefully someone else in this forum can come up more troubleshooting ideas so you can get to the bottom of it.

    Also, if you think the exact condition for this exception to occur is only on "0," then you have a workaround (which is obvious.)

    Brian



  • APSrinu

    This is the version that I am seeing the problem:

    Microsoft Visual Studio 2005
    Version 8.0.50727.42  (RTM.050727-4200)
    Microsoft .NET Framework
    Version 2.0.50727

    Installed Edition: Professional



  • TheDoctor30306

    I've never had a beta version on the two systems I've recreated this on.  I have had VS2003 on the systems before.

    On one system I tested a side by side install of VS2003 and VS2005, on the other system I uninstalled VS2003 and all .net framework installs before installing VS2005.

  • dkpagan

    Strange.  Have you tried isolating it down to a simple executable  
  • Pamela.Clark

    Maybe the culture is affecting this   (I don't have any experience with this.)

    My assembly.cs has:

    [assembly: AssemblyCulture("")]

    Under Control Panel->Regional and Language Options, I'm set to English(United States), but it would be tidious to compare every setting below that (I've never touched this.)

    Brian


  • Cocotteseb

    FWIW, I'm not getting that problem against VS 2005 b2 (getting closer to obtaining VS 2005 RTM in my measly graduate school existence).  I created a C# console project and entered:

    static void Main(string[] args)
    {
       int x1, x2, x3, x4;
       x1 =
    Int32.Parse("0"); // works fine
       x2 = Int32.Parse("00"); // works fine
       x3 = Int32.Parse("000"); // works fine
       x4 = Int32.Parse("0000"); // works fine
    }


  • Alex_Sig

    My AssemblyCulture is set the same as yours (the default), and my regional settings are the same.

    I'm hoping someone using the same version (we downloaded the iso from MSDN last week) will be able to reproduce the problem.  I can't find anywhere to report a bug without starting a support incident, which seems a bit extreme.

    This kind of bug will keep our team from switching over from VS2003 to VS2005.  If this got through QA, I don't want to know what else slipped by.

  • david.tooley

    Doesn't get much simpler than this...  Using the version I specified in a post above, this will throw an exception.

    namespace IntParse
    {
        class Program
        {
            static void Main(string[] args)
            {
                int x = Int32.Parse("0");
            }
        }
    }

  • bug in Int32.Parse