Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception thrown: 'System.OverflowException' in mscorlib.dl #12

Open
RocklinSoftware opened this issue Jun 23, 2017 · 4 comments
Open

Comments

@RocklinSoftware
Copy link

RocklinSoftware commented Jun 23, 2017

Hi Cubico,

You did a nice job on your application.

I am getting an error in a Web-Application project using v1.1.0.

A) In the Web-Application Cubico ATTEMPT 1 works and Cubico ATTEMPT 2 fails.
B) If I rollback your software to 1.0.1 Cubico ATTEMPT 1 works and Cubico ATTEMPT 2 works.

Any help is appreciated.

Thank you,
Dave
RocklinSoftware.com, Susanville, CA
SEE LAST POST.

This was in the Cubico code. Looked interesting. (? Cubico/Src/Cubico/UnitConverter.cs)
//TODO: Fix this; was Previously NaN
const double _failsafeValue = 0;
public Dictionary<string, Unit> _SymbolDictionary;
Dictionary<string, Symbol> _IndividualSymbolDictionary;
Dictionary<string, Unit> _UnitDictionary;
Dictionary<string, UnitType> _UnitTypeDictionary;
// Constructor, sets up the unit converter.

----- Web-Application Code
protected void Session_Start(object sender, EventArgs e) // WEBSITE
{
try
{
double value = Convert.ToDouble(2.2);
string c1 = "in";
string t1 = "cm";

            Cubico.UnitConverter target = new Cubico.UnitConverter();
            var v1 = target.ConvertUnits(value, c1, t1).ToString(); // CURRENT, TARGET
            var q1 = v1;
        }
        catch (Exception ex)
        {
            var message = ex.Message;
            throw;
        }

        if (Request.IsAuthenticated) // SETUP
        {
            using (ApplicationDbContext dbContext2 = new ApplicationDbContext())
            {
                try
                {
                    string email = "";
                    string id = User.Identity.GetUserId();

                    email = (from user in dbContext2.Users where user.Id == id select user.Email).First();
                    l.Initialize(Request.IsAuthenticated, User.Identity.GetUserId(), User.Identity.GetUserName(), email);
                }
                catch (Exception ex) // TODO: remove
                {
                    var message = ex.Message;
                    l.Set_AlertMessage("global error email");
                    l.Initialize(Request.IsAuthenticated, User.Identity.GetUserId(), User.Identity.GetUserName(), "global error, email");
                }
            }
        }
        else
        {
            l.Initialize(Request.IsAuthenticated, User.Identity.GetUserId(), User.Identity.GetUserName(), "");
        }

        try
        {
            double value = Convert.ToDouble(2.2);
            string c1 = "in";
            string t1 = "cm";

            Cubico.UnitConverter target = new Cubico.UnitConverter(); // FAILURE
            var v1 = target.ConvertUnits(value, c1, t1).ToString(); // CURRENT, TARGET
            var q1 = v1;
        }
        catch (Exception ex)
        {
            var message = ex.Message; // ERROR
            throw;
        }
    }

EXCEPTION THROWN: Exception thrown: 'System.OverflowException' in mscorlib.dll
BAD MESSAGE: "Value was either too large or too small for a Decimal."
BAD STACK TRACE: " at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)\r\n at System.Convert.ToDecimal(String value)\r\n at Cubico.UnitProvider.ProcessUnitConverterData2(RootObject RootObject) in c:\Users\Ivan\Source\Repos\Cubico\Src\Cubico\UnitProvider.cs:line 125\r\n at Cubico.UnitProvider.LoadJsonDataFile() in c:\Users\Ivan\Source\Repos\Cubico\Src\Cubico\UnitProvider.cs:line 115\r\n at Cubico.UnitConverter..ctor() in c:\Users\Ivan\Source\Repos\Cubico\Src\Cubico\UnitConverter.cs:line 27\r\n at Ii.Website.MvcApplication.Session_Start(Object sender, EventArgs e) in C:\Users\euser\Desktop\CODEBASE\Solution\Ii.Website\Global.asax.cs:line 64"

@RocklinSoftware
Copy link
Author

RocklinSoftware commented Jun 23, 2017

Cleaned up my comments. - Thanks again...

@RocklinSoftware
Copy link
Author

RocklinSoftware commented Jun 23, 2017

Hi Cubico,

I believe I have located the problem. You application uses the default language en-US. My application uses en-US and other language threads.

Here is a console application that shows the issue for your edification. I will leave the Issue open. You can close when you want. I will managed this on my side by localizing. Nice job on you application.

Thanks,
Dave from Rocklin Software Susanville, CA

// (c) 2016-2017 Rocklin Software - Information for Cubico

using Cubico;

using System;
using System.Globalization;
using System.Threading;

namespace Ii.Ecommerce.WhiteBox
{
class ClientProgram
{
static void Main(string[] args)
{
Console.WriteLine("Cubico Start");
var defaultCurrentThread1 = Thread.CurrentThread.CurrentCulture.Name; // DEFUALT en-US
var defaultCurrentUICulture1 = Thread.CurrentThread.CurrentUICulture.Name;

     // ----------------------------------------------------------------------  //
     Console.WriteLine("");
     Console.WriteLine(">Cubico de-DE");
     var cultureInfo2 = new CultureInfo("de-DE"); // TO GERMAN
     Thread.CurrentThread.CurrentCulture = cultureInfo2;
     Thread.CurrentThread.CurrentUICulture = cultureInfo2;

     try
     {
        double doubleValue = Convert.ToDouble(2.2);
        Console.WriteLine(">"+doubleValue); // SEE CONSOLE; 2,2 BECAUSE de-DE
        string currentUnitName = "in";
        string targetUnitName = "cm";
        TestCode testCode = new TestCode(); // TEST
        testCode.CubicoMethod(doubleValue, currentUnitName, targetUnitName);
     }
     catch (Exception ex)
     {
        var message = ex.Message;
     }

     // ----------------------------------------------------------------------  //
     Console.WriteLine("");
     Console.WriteLine(">Cubico en-US");
     var cultureInfo = new CultureInfo("en-US");
     Thread.CurrentThread.CurrentCulture = cultureInfo;
     Thread.CurrentThread.CurrentUICulture = cultureInfo;

     try
     {
        double doubleValue = Convert.ToDouble(2.2);
        Console.WriteLine(">" + doubleValue); // SEE CONSOLE; 2.2 BECAUSE en-US
        string currentUnitName = "in";
        string targetUnitName = "cm";
        TestCode testCode = new TestCode(); // TEST
        testCode.CubicoMethod(doubleValue, currentUnitName, targetUnitName);
     }
     catch (Exception ex)
     {
        var message = ex.Message;
     }

     Console.WriteLine("");
     Console.WriteLine("Cubico Stop");
     Console.ReadLine();
  }

}
public class TestCode
{
public void CubicoMethod(double _doubleValue, string _currentUnitName, string _targetUnitName)
{
try
{
UnitConverter target = new UnitConverter();
var v1 = target.ConvertUnits(_doubleValue, _currentUnitName, _targetUnitName); // CURRENT, TARGET
Console.WriteLine(">Console Success in " + Thread.CurrentThread.CurrentUICulture.Name);
}
catch (Exception ex)
{
Console.WriteLine(">Console Error in "+ Thread.CurrentThread.CurrentUICulture.Name);
var message = ex.Message;
throw; // GO BACK and CONTINUE
}
}
}
}

@irperez
Copy link
Owner

irperez commented Jun 27, 2017

Sorry for my delayed response. I'll take a look. Thanks for finding this issue.

@irperez
Copy link
Owner

irperez commented Aug 16, 2017

@RocklinSoftware I was able to replicate your issue thanks to your detailed repro steps!

The problem was in how I read the xml/json data from the file. String -> Decimal conversion. I'm now using CultureInfo.InvariantCulture to parse the decimal.

I took your example as a unit test and it works as expected.

I've checked in the code. I have yet to create a new nuget package. But feel free to recompile the repo until I can get another nuget package out there.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants