I have a C# asp.net web application which connects to a MySQL database. Intermittently with one user, I am getting a System.FormatException when trying to list the results from the database.
The exception occurrs when we call products.ToList() in the function below:
private void ReloadCache()
{
var products = _context.Products.
Include(p => p.Category).
Include(p => p.Protocols).
Include(p => p.LocalizedDetails.Select(pl => pl.Language)).
Include(p => p.Costs.Select(pc => pc.Region.Currency));
_productCache = products.ToList(); // exception thrown here
}
In the stack trace, I can see the exception is actually thrown when trying to read a value from the database, and converting it to a decimal:
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.TypeInitializationException: The type initializer for 'Cylon.QuoteEngine.Application.Web.BasePage' threw an exception. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Convert.ToDecimal(String value, IFormatProvider provider)
at System.Convert.ToDecimal(Object value)
at MySql.Data.MySqlClient.MySqlDataReader.GetDecimal(Int32 i)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetTypedValueDefault(DbDataReader reader, Int32 ordinal)
at System.Data.Common.Internal.Materialization.Shaper.ErrorHandlingValueReader`1.GetValue(DbDataReader reader, Int32 ordinal)
at System.Data.Common.Internal.Materialization.Shaper.GetPropertyValueWithErrorHandling[TProperty](Int32 ordinal, String propertyName, String typeName)
at lambda_method(Closure , Shaper )
at System.Data.Common.Internal.Materialization.Shaper.HandleEntityAppendOnly[TEntity](Func`2 constructEntityDelegate, EntityKey entityKey, EntitySet entitySet)
at lambda_method(Closure , Shaper )
at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
at System.Data.Common.Internal.Materialization.Shaper`1.RowNestedResultEnumerator.MoveNext()
at System.Data.Common.Internal.Materialization.Shaper`1.ObjectQueryNestedEnumerator.TryReadToNextElement()
at System.Data.Common.Internal.Materialization.Shaper`1.ObjectQueryNestedEnumerator.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Cylon.QuoteEngine.Persistence.ProductRepository.ReloadCache()
I can catch the FormatException with a try catch block, but I do not have any more information on what string is failing to convert, or what table or column it is reading from. It merely states the issue occurred and I am none the wiser.
This application has been running for a couple years already, and only recently with one user has this issue started to intermittently occur. I have inspected the data in my DB, and ensured that the types match what is expected.
Is there a way to get information on the string, column, table or anything else that I can use to determine what is happening?
FormatException'sInnerExceptionproperty?