Cannot unbox .. to "decimal" when calling a field from the database

Posts   
 
    
Posts: 64
Joined: 30-Aug-2010
# Posted on: 19-Apr-2011 16:49:28   

Hello

I am using LLBL 3.0, with Oracle. After generaiting the classes, and starting the application, at some point when a value from the database is needed, I am getting the folowing error message:

Cannot unbox  ..  to "decimal"

here is where the error occurs:

public virtual System.Decimal ARBFI_QTACIO { get { return (System.Decimal)GetValue((int)ARBO_FINAFieldIndex.ARBFI_QTACIO, true); } set { SetValue((int)ARBO_FINAFieldIndex.ARBFI_QTACIO, value); } }

This is a field from my entity, and when the :

return (System.Decimal)GetValue((int)ARBO_FINAFieldIndex.ARBFI_QTACIO, true);

is executed, there is where this error occurs.

In the database, this field is of type: NUMBER (15,5), the Generated .Net types is Double. I made a type converter to change it to Decimal.

I think that for the code to work fine, it would have to return something like this:

return (System.Decimal)[b](int)[/b]GetValue((int)ARBO_FINAFieldIndex.ARBFI_QTACIO, true);

Could you please help with some tips? Thank you

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 19-Apr-2011 22:04:59   

I'm slightly confused as to why, if your field is defined as a NUMBER(15,5), you're seeing an (int) in the generated code...disappointed

Do you get the same result if you try it without the TypeConverter in place ?

Matt

Posts: 64
Joined: 30-Aug-2010
# Posted on: 20-Apr-2011 08:56:54   

Good Morning,

So, If I don't add the type converter, the regenerated code looks like this:

public virtual System.Double ARBFI_QTACIO
        {
            get { return (System.Double)GetValue((int)ARBO_FINAFieldIndex.ARBFI_QTACIO, true); }
            set { SetValue((int)ARBO_FINAFieldIndex.ARBFI_QTACIO, value); }
        }

I tested with it too, and the same error message occurs cry

I also attached my type converter.

Attachments
Filename File size Added on Approval
SingleDecimalConverter.cs 4,337 20-Apr-2011 08:57.14 Approved
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Apr-2011 09:27:06   

Could you show the stack trace of where the "Cannot unbox ..." exception occurs?

Posts: 64
Joined: 30-Aug-2010
# Posted on: 20-Apr-2011 10:06:28   

Hello, Here is the stack.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 20-Apr-2011 11:04:33   

Invalid images. Please post the stacktrace just a text here. It's ascii after all...

Frans Bouma | Lead developer LLBLGen Pro
Posts: 64
Joined: 30-Aug-2010
# Posted on: 20-Apr-2011 11:34:46   

Ok, Sorry. Here it is again

SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll!SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.GetValue(int fieldIndex = 16, bool returnDefaultIfNull = true) ASTech.LLBL.dll!ASTech.LLBL.EntityClasses.ARBO_FINAEntity.ARBFI_QTACIO.get() Line 669 + 0x13 bytes C# [Native to Managed Transition] [Managed to Native Transition] System.dll!System.ComponentModel.ReflectPropertyDescriptor.GetValue(object component = {ASTech.LLBL.EntityClasses.ARBO_FINAEntity}) + 0xd9 bytes System.Windows.Forms.dll!System.Windows.Forms.BindToObject.GetValue() + 0x42 bytes System.Windows.Forms.dll!System.Windows.Forms.Binding.PushData(bool force) + 0x81 bytes System.Windows.Forms.dll!System.Windows.Forms.Binding.UpdateIsBinding() + 0x8b bytes System.Windows.Forms.dll!System.Windows.Forms.ListManagerBindingsCollection.AddCore(System.Windows.Forms.Binding dataBinding) + 0x37 bytes System.Windows.Forms.dll!System.Windows.Forms.BindingsCollection.Add(System.Windows.Forms.Binding binding) + 0x50 bytes System.Windows.Forms.dll!System.Windows.Forms.BindingContext.UpdateBinding(System.Windows.Forms.BindingContext newBindingContext, System.Windows.Forms.Binding binding) + 0xe4 bytes System.Windows.Forms.dll!System.Windows.Forms.Binding.SetBindableComponent(System.Windows.Forms.IBindableComponent value = {Text = ""}) + 0xc2 bytes System.Windows.Forms.dll!System.Windows.Forms.ControlBindingsCollection.AddCore(System.Windows.Forms.Binding dataBinding) + 0x36 bytes System.Windows.Forms.dll!System.Windows.Forms.BindingsCollection.Add(System.Windows.Forms.Binding binding) + 0x50 bytes ASTech.Office.exe!ASTech.Office.ListFormManager.InitializeBindings(System.Windows.Forms.Control oContainer = {ASTech.UC.dbSection, BorderStyle: System.Windows.Forms.BorderStyle.None}) Line 1284 + 0x36 bytes C# ASTech.Office.exe!ASTech.Office.ListFormManager.InitializeBindings(System.Windows.Forms.Control oContainer = {System.Windows.Forms.Panel, BorderStyle: System.Windows.Forms.BorderStyle.None}) Line 1530 + 0x10 bytes C# ASTech.Office.exe!ASTech.Office.ListFormManager.GetAndBindData() Line 1044 + 0x16 bytes C# ............................

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 20-Apr-2011 12:04:33   

When you place a breakpoint on the get { } clause (where the exception occurs), run in debug mode and when the breakpoint hits, in the intermediate window of vs.net (or watch window) look at the value which is returned by: GetValue((int)ARBO_FINAFieldIndex.ARBFI_QTACIO, true)

what is the type of the value? It looks like it's not a double and not a decimal

Frans Bouma | Lead developer LLBLGen Pro
Posts: 64
Joined: 30-Aug-2010
# Posted on: 20-Apr-2011 13:10:32   

Hello.

In the watch window, for the: GetValue((int)ARBO_FINAFieldIndex.ARBFI_QTACIO, true).GetType()

This is the result: {Name = "Int32" FullName = "System.Int32"} System.Type {System.RuntimeType}.

So, yes indeed, the type is not a double nor a decimal.

This field, can have null values. So, in my type converter, when null value is encountered, I return 0.

I have changed in the typeConverter, to return (decimal)0, and I think this was it.

I am still doing some testing, but thank thousand times.