I get the following error when I run my application. It was working fine in 3.5. I am facing this issue when we migrated to .Net 4.0. Has anything changed in 4.0 types or something else which is causing this?
Any response is greatly appreciated in advance.
[FormatException: Input string was not in a correct format.]
<div>Hi,</div> <div></div> <div>Try to debug the code. It looks like you are trying to parse the integer without any value in it. Alos you can search for the line whihc has ToInt conversion and make sure you are passing a value in the variable.</div> <div></div>
<div></div>
This is all the error I got. I have probably put 100 breakpoints in the code and debugged. No use. Its surprising since the code was just working fine in the 3.5. It stopped working once we migrated to 4.0.
Convert.ToInt32() can also cause this FormatException.
Check for int.Parse() and Convert.ToInt32() in your code.
string input = Console.ReadLine();
// ToInt32 can throw FormatException or OverflowException. try
{
numVal = Convert.ToInt32(input);
} catch (FormatException e)
{
Console.WriteLine("Input string is not a sequence of digits.");
} catch (OverflowException e)
{
Console.WriteLine("The number cannot fit in an Int32.");
}
We found out that certain bound fields in the grid were causing this problem. We replaced the bound fields with template fields and it worked. This started happening once we moved to .NET 4.0. Not sure what was the issue.
We found out that certain bound fields in the grid were causing this problem. We replaced the bound fields with template fields and it worked. This started happening once we moved to .NET 4.0. Not sure what was the issue.
You mean the .NET Framework was showing the wrong error?
When migrating to .NET 4.0 we have to replace bound fields with template fields? That doesnt make sense.
pgnaregal
Member
14 Points
3 Posts
System.FormatException: Input string was not in a correct format.
Mar 11, 2011 06:09 AM|LINK
I get the following error when I run my application. It was working fine in 3.5. I am facing this issue when we migrated to .Net 4.0. Has anything changed in 4.0 types or something else which is causing this?
Any response is greatly appreciated in advance.
Slicksim
Participant
1925 Points
350 Posts
Re: System.FormatException: Input string was not in a correct format.
Mar 11, 2011 09:09 AM|LINK
Hi,
What is the value that is being passed in?
Si
asheejtk
Participant
1114 Points
200 Posts
Re: System.FormatException: Input string was not in a correct format.
Mar 11, 2011 10:00 AM|LINK
Asheej T K
Dotnet Galaxy
jerryjoseph
Contributor
6740 Points
1257 Posts
Re: System.FormatException: Input string was not in a correct format.
Mar 11, 2011 10:08 AM|LINK
Identify which line of code caused the error (must be mentioned in the error).
Paste the line.
The link below describes changes that have been made for the .NET Framework version 4 release that can potentially affect applications that were created using earlier releases.
http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes
linkedin | twitter | www.jerryjoseph.net
pgnaregal
Member
14 Points
3 Posts
Re: System.FormatException: Input string was not in a correct format.
Mar 11, 2011 11:24 AM|LINK
This is all the error I got. I have probably put 100 breakpoints in the code and debugged. No use. Its surprising since the code was just working fine in the 3.5. It stopped working once we migrated to 4.0.
jerryjoseph
Contributor
6740 Points
1257 Posts
Re: System.FormatException: Input string was not in a correct format.
Mar 11, 2011 11:35 AM|LINK
From the error it seems like you are trying to invoke the method StringToNumber() in some GridView event.
Search for that method in your solution or in the page causing the error.
linkedin | twitter | www.jerryjoseph.net
Wenchao Zeng...
Star
14673 Points
1496 Posts
Re: System.FormatException: Input string was not in a correct format.
Mar 15, 2011 05:54 AM|LINK
Hi,
Have you figured out the cause and resolved the issue? Otherwise, can you share the code including both aspx markup and code behind with us?
In case you don't know which line will probably cause this issue, below is a code snippet which will reproduce this issue:
// Error: Input string was not in a correct format.
int i = int.Parse("Not a valid integer.");
Thanks,
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
jerryjoseph
Contributor
6740 Points
1257 Posts
Re: System.FormatException: Input string was not in a correct format.
Mar 15, 2011 09:54 AM|LINK
Convert.ToInt32() can also cause this FormatException.
Check for int.Parse() and Convert.ToInt32() in your code.
string input = Console.ReadLine();
// ToInt32 can throw FormatException or OverflowException.
try
{
numVal = Convert.ToInt32(input);
}
catch (FormatException e)
{
Console.WriteLine("Input string is not a sequence of digits.");
}
catch (OverflowException e)
{
Console.WriteLine("The number cannot fit in an Int32.");
}
http://msdn.microsoft.com/en-us/library/bb397679.aspx
linkedin | twitter | www.jerryjoseph.net
pgnaregal
Member
14 Points
3 Posts
Re: System.FormatException: Input string was not in a correct format.
Apr 08, 2011 08:45 AM|LINK
It was not an integer parsing problem.
We found out that certain bound fields in the grid were causing this problem. We replaced the bound fields with template fields and it worked. This started happening once we moved to .NET 4.0. Not sure what was the issue.
jerryjoseph
Contributor
6740 Points
1257 Posts
Re: System.FormatException: Input string was not in a correct format.
Apr 11, 2011 06:31 AM|LINK
You mean the .NET Framework was showing the wrong error?
When migrating to .NET 4.0 we have to replace bound fields with template fields? That doesnt make sense.
linkedin | twitter | www.jerryjoseph.net