1
Vote

Exception after save when CurrentCulture = enGB

description

On editing an entry in the grid and clicking Save button receive an unhandled exception as follows:
 
Price is malformed or not a valid value.
Description: An unhandled exception occurred <...snip...>
 
Exception Details: <...snip...>
 
Line 74: internal void PersistChanges(ProductEditView view)
Line 75: {
Line 76: Product newProduct = ProductEditView.ToProduct(view);
Line 77: Product oldProduct = this._repository.GetProductById(newProduct.ProductId);
Line 78:

Source File: D:\downloads\VMWorkshopCS\VMWorkshop.Web\Models\ViewModels\WebFormsViewModel.cs Line: 76
 
Stack Trace:
 
[ArgumentException: Price is malformed or not a valid value.]
VMWorkshop.Domain.ProductEditView.ToProduct(ProductEditView view) in C:\Users\cshoemaker\Projects\WorkFiles\VMWorkshop\trunk\src\csharp\VMWorkshop.Domain\ProductEditView.cs:55
VMWorkshop.Web.Models.ViewModels.WebFormsViewModel.PersistChanges(ProductEditView view) in D:\downloads\VMWorkshopCS\VMWorkshop.Web\Models\ViewModels\WebFormsViewModel.cs:76
VMWorkshop.Web.WebForms.btnSave_Click(Object sender, EventArgs e) in D:\downloads\VMWorkshopCS\VMWorkshop.Web\Demos\WebForms.aspx.cs:36
 
(Refers to webforms app in download of v1)
 
A work-around for this exception is to edit the currency symbol to be a $ (dollar) instead of a £ (UK sterling) symbol.

comments

rohancragg wrote Jan 7, 2010 at 3:52 PM

The simple fix is:

ProductEditView - line 49

replace:

if (double.TryParse(view.Price.TrimStart('$'), out db))

with:

if (double.TryParse(view.Price.TrimStart(NumberFormatInfo.CurrentInfo.CurrencySymbol.ToCharArray()), out db))

and add:

using System.Globalization;

wrote Feb 13, 2013 at 3:54 AM