using double; System.InvalidCastException: Specified cast is not valid

Jul 16, 2008 at 2:11 PM
When I use

[EditableTextBox("Double Test", 0, 800, ContainerName = "tabTeksten")]
    public virtual double d
    {
        get { return (double)(GetDetail("d") ?? 0); }
        set { SetDetail("d", value); }
    }

I get this error when editting (actually when loading in edit.aspx):

Server Error in '/' Application.

Specified cast is not valid.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidCastException: Specified cast is not valid.

Source Error:

Line 30:     public virtual double d
Line 31: {
Line 32: get { return (double)(GetDetail("d") ?? 0); }
Line 33: set { SetDetail("d", value); }
Line 34: }

Source File: D:\www\SA_NotebookOnline\SA_NotebookOnline\cPageItems\Homepage.cs    Line: 32

Stack Trace:

[InvalidCastException: Specified cast is not valid.]
PageItemHomepage.get_d() in D:\www\SA_NotebookOnline\SA_NotebookOnline\cPageItems\Homepage.cs:32

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +72
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +308
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) +55
System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index) +18
N2.Utility.Evaluate(Object item, String expression) +148
N2.ContentItem.get_Item(String detailName) +355
N2.Details.EditableTextBoxAttribute.UpdateEditor(ContentItem item, Control editor) +77
N2.Edit.EditManager.UpdateEditors(ContentItem item, IDictionary`2 addedEditors, IPrincipal user) +332
N2.Web.UI.WebControls.ItemEditor.CreateChildControls() +261
System.Web.UI.Control.EnsureChildControls() +87
N2.Web.UI.WebControls.ItemEditor.set_CurrentItem(ContentItem value) +172
N2.Edit.Edit.InitItemEditor() +384
N2.Edit.Edit.OnInit(EventArgs e) +246
System.Web.UI.Adapters.ControlAdapter.OnInit(EventArgs e) +12
System.Web.UI.Control.InitRecursive(Control namingContainer) +2120365
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +834


Version Information: Microsoft .NET Framework Version:2.0.50727.1434; ASP.NET Version:2.0.50727.1434


I did not expect this, but I guess I am doing something wrong?
Coordinator
Jul 16, 2008 at 9:29 PM
Try

        get { return (double)(GetDetail("d") ?? 0.0); }

Can't explain why. Apparently C# takes types very seriosly.
Jul 17, 2008 at 12:52 PM
lol, good to know that zero is not zero unless it is zero with even more nothing :-)

Thanks!