Why the double.Parse throw error in live server and how to track?
I build a website, that:
- reads data from a website by HttpWebRequest
- Sort all Data
- Parse values of the data
- and give out newly
On local server it works perfect, but when I push it to my live server, the double.Parse fails with an error.
So: - how to track what the double.parse is tr开发者_Python百科ying to parse? - how to debug live server?
Lang is ASP.Net / C#.net 2.0
You probably have culture issues.
Pass CultureInfo.InvariantCulture
to double.Parse
and see if it helps.
To see the exception on the server, add <customErrors mode="Off" />
to the <system.web>
element in web.config. (And make sure to remove it afterwords)
Alternatively, you can setup a real error logging system, such as ELMAH, or check the server's event log.
Sounds like a problem with regional settings and the decimal separator. Might be different in your development/live servers.
I would use TryParse instead of just plain Parse. That way, you would control what is being intended to parse.
Like this.
double outval;
if (!double.TryParse(yourvar, out outval)) {
// throw and manage error on your website
}
// life goes on.
精彩评论