c# - ParseBigInteger FormatException in RavenDB source code -


in our wpf app have input validation. 1 of input values decimal , allows max of 28 digits (like 999999999999999999999999999). 1 more 9 , gives validation error feedback, 28 9's work intended.

however, when try save ravendb gives bigintegerparse formatexception , can't figure out why. thought size of biginteger infinite (if i'm not mistaken has byte-max equal integer.max_value, although i'm not sure). still, assume biginteger parse have no trouble converting string 28 9's biginteger.

here part of stacktrace:

system.formatexception: value not parsed.    @ system.numerics.bignumber.parsebiginteger(string value, numberstyles style, numberformatinfo info)    @ raven.imports.newtonsoft.json.jsontextreader.parsenumber() in c:\builds\ravendb-stable-3.0\imports\newtonsoft.json\src\newtonsoft.json\jsontextreader.cs:line 1288    @ raven.imports.newtonsoft.json.jsontextreader.parsevalue() in c:\builds\ravendb-stable-3.0\imports\newtonsoft.json\src\newtonsoft.json\jsontextreader.cs:line 1010    @ raven.imports.newtonsoft.json.jsontextreader.readinternal() in c:\builds\ravendb-stable-3.0\imports\newtonsoft.json\src\newtonsoft.json\jsontextreader.cs:line 383    @ raven.imports.newtonsoft.json.jsontextreader.read() in c:\builds\ravendb-stable-3.0\imports\newtonsoft.json\src\newtonsoft.json\jsontextreader.cs:line 304    @ raven.json.linq.ravenjobject.load(jsonreader reader) in c:\builds\ravendb-stable-3.0\raven.abstractions\json\linq\ravenjobject.cs:line 251    @ raven.json.linq.ravenjobject.load(jsonreader reader) in c:\builds\ravendb-stable-3.0\raven.abstractions\json\linq\ravenjobject.cs:line 211    @ raven.json.linq.ravenjobject.load(jsonreader reader) in c:\builds\ravendb-stable-3.0\raven.abstractions\json\linq\ravenjobject.cs:line 211    @ raven.json.linq.ravenjarray.load(jsonreader reader) in c:\builds\ravendb-stable-3.0\raven.abstractions\json\linq\ravenjarray.cs:line 139    ... 

i've looked source code of first stacktrace line (c:\builds\ravendb-stable-3.0\imports\newtonsoft.json\src\newtonsoft.json\jsontextreader.cs:line 1288) , found here: ravendb jsontextreader.

line 1288 has following code:

1284        else if (parseresult == parseresult.overflow) 1285        { 1286    #if !(net20 || net35 || silverlight || portable40 || portable) 1287            string number = _stringreference.tostring(); {1288}          numbervalue = biginteger.parse(number, cultureinfo.invariantculture); 1289            numbertype = jsontoken.integer; 1290    #else 1291            // todo - validate number valid integer make sure overflow reason failure 1292            throw jsonreaderexception.create(this, "json integer {0} large or small int64.".formatwith(cultureinfo.invariantculture, _stringreference.tostring())); 1293    #endif 1294        } 

so, question: max value parser can hold in ravendb source code? if knew max can adjust validation class use set max, instead of default decimal's max. (we use ravendb save event-states , our project uses cqrs architecture.)

looks problem in how ravendb deserializes json. here's sample. let's declare sample model:

public class foo {     public decimal bar { get; set; } } 

...and serialize json:

var serializer = new jsonserializer(); var sb = new stringbuilder(); var foo = new foo {     bar = 9999999999999999999999999999m };  using (var textwriter = new stringwriter(sb)) using (var jsonwriter = new jsontextwriter(textwriter)) {     serializer.serialize(jsonwriter, foo); }  debug.writeline(sb); 

output contain this:

{"bar":9999999999999999999999999999.0}

note, there's fractional part in string representation. of course, if try parse value biginteger (as ravendb does), you'll formatexception, because string invalid biginteger.

what here? honestly, don't know... may be, better store data in model biginteger, if is big integer?


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -