locked
Custom Control reports rendering error in VS designer RRS feed

  • Question

  • User1780761961 posted

     Hi,

    My custom controls don't render correctly in the Visual Studio page designer when I add them to an aspx page and set one of the custom properties. It's only the render in design mode that fails in all other respects it works fine. To illustrate I've simplied my control to the following:

    Control.cs

        [ToolboxData("<{0}:TestTextBox ID=TestTextBox1 runat=server></{0}:TestTextBox>")]
        public class TestTextBox : TextBox
        {
    
            public bool TestRequired
            {
                get
                {
                    if (ViewState["TestRequired"] == null)
                        return false;
                    else
                        return (bool)ViewState["TestRequired"];
                }
                set { ViewState["TestRequired"] = value; }
            }
        }

    ----------------------------------------------------

    Control.apsx

    <csc:TestTextBox ID="test1" runat="server" ReadOnly="true" TestRequired="true"></csc:TestTextBox>

    --------------------------------------------------------------------------------

    On the design page the following error is reported:

    an unhandled exception has occurred. 'true' could not be set on property 'TestRequired'.

    I'm able to set the value in design mode & programmtically at run time and the control functions as I want, but in design mode it doesn't render the control correctly which i'm confused by.

    I'm using Visual Studio 2008 .Net Framework 3.5 SP1 on Windows XP.

    Any help greatly appreciated.

    Regards,

    Harj

    Monday, July 27, 2009 4:31 AM

Answers

  • User-2106054853 posted

     Hi,

    It looks like an IDE issue. Please submit a feedback to https://connect.microsoft.com/VisualStudio. Our dedicated engineers will work with you on this issue.

    The root cause is probably dll mismatch in the following folder:

    C:\Users\yourusername\AppData\Local\Microsoft\VisualStudio\9.0\ProjectAssemblies

    More information:

     

    0:000> !printexception
    Exception object: 04310cfc
    Exception type: System.InvalidCastException
    Message: [A]WebApplication2.TestTextBox cannot be cast to [B]WebApplication2.TestTextBox. Type A originates from 'WebApplication2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location 'C:\Users\allenc\AppData\Local\Microsoft\VisualStudio\9.0\ProjectAssemblies\d_kkawks01\WebApplication2.DLL'. Type B originates from 'WebApplication2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location 'C:\Users\allenc\AppData\Local\Microsoft\VisualStudio\9.0\ProjectAssemblies\lnh3lpju01\webapplication2.dll'.
    InnerException: <none>
    StackTrace (generated):
    <none>
    StackTraceString: <none>
    HResult: 80004002


    0:000> !clrstack
    OS Thread Id: 0x322c (0)
    ESP       EIP    
    002de7e8 75bef35f [HelperMethodFrame_1OBJ: 002de7e8]
    002de848 0ec865e6 Unknown MethodDesc (Module 14aad248, mdToken 0600000b)
    002de858 0c7676c8 System.Web.Util.FastPropertyAccessor.SetProperty(System.Object, System.String, System.Object)
    002de86c 0c766375 System.Web.UI.PropertyMapper.SetMappedPropertyValue(System.Object, System.String, System.Object)
    002de87c 0c6a2ccf System.Web.UI.ControlBuilder.SetSimpleProperty(System.Web.UI.SimplePropertyEntry, System.Object)
    002de8ac 0c6a2c12 System.Web.UI.ControlBuilder.InitSimpleProperties(System.Object)
    002de8d8 0c6a2a97 System.Web.UI.ControlBuilder.InitObject(System.Object)
    002de8f0 0c6a247f System.Web.UI.ControlBuilder.BuildObjectInternal()
    002de904 0c6a2315 System.Web.UI.ControlBuilder.BuildObject()
    002de908 0c6a2381 System.Web.UI.ControlBuilder.BuildObject(Boolean)
    002de91c 0c774221 System.Web.UI.DesignTimeTemplateParser.ParseControlsInternal(System.Web.UI.DesignTimeParseData, Boolean)
    002de960 0c774409 System.Web.UI.DesignTimeTemplateParser.ParseControl(System.Web.UI.DesignTimeParseData)
    002de968 50e1935b System.Web.UI.Design.ControlSerializer.DeserializeControlInternal(System.String, System.ComponentModel.Design.IDesignerHost, Boolean)
    002de9a0 50e16960 System.Web.UI.Design.ControlParser.ParseControl(System.ComponentModel.Design.IDesignerHost, System.String, Boolean)
    002de9b8 50e12271 System.Web.UI.Design.ControlDesigner.CreateClonedControl(System.ComponentModel.Design.IDesignerHost, Boolean)
    002de9d4 50e11e65 System.Web.UI.Design.ControlDesigner.CreateViewControl()
    002de9e4 50e11ec3 System.Web.UI.Design.ControlDesigner.CreateViewControlInternal()
    002de9fc 50e12515 System.Web.UI.Design.ControlDesigner.get_ViewControl()
    002dea10 50e13004 System.Web.UI.Design.ControlDesigner.GetDesignTimeHtml()
    002dea50 50e130f7 System.Web.UI.Design.ControlDesigner.GetDesignTimeHtml(System.Web.UI.Design.DesignerRegionCollection)
    002dea60 50e14995 System.Web.UI.Design.ControlDesigner.GetViewRendering(System.Web.UI.Design.ControlDesigner)
    002dea9c 50e14aa6 System.Web.UI.Design.ControlDesigner.GetViewRendering()
    002deab0 0f58ec84 Microsoft.Web.Design.ElementDesigner.UpdateView(Boolean)
    002deae8 0b2663f2 Microsoft.Web.Design.ElementDesigner.System.Web.UI.Design.IControlDesignerView.Update()
    002deaec 50e138dc System.Web.UI.Design.ControlDesigner.UpdateDesignTimeHtml()
    002deb00 50e144bf System.Web.UI.Design.ControlDesigner.OnComponentChanged(System.Object, System.ComponentModel.Design.ComponentChangedEventArgs)
    002deb4c 0b266362 Microsoft.Web.Design.DocumentDesigner.OnComponentChanged(System.Object, System.ComponentModel.Design.ComponentChangedEventArgs)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 29, 2009 4:51 AM

All replies

  • User-16411453 posted

    You declared TestRequired as Boolean, you have to remove the double quotes around it it think

    if (ViewState["TestRequired"] == null)


    if (ViewState[TestRequired] == null)


    I use this

    <Bindable(True)> _
    	<Category("Behavior")> _
    	<Description("Set the operatonal mode of the control, Debug for testing")> _
    	<DefaultValue("False")> _
    	<Localizable(True)> _
    	Public Property Debug_Mode() As Boolean
    		Get
    			Dim _Debug_Mode As Boolean = Convert.ToBoolean(ViewState("Debug_Mode"))
    			If _Debug_Mode = Nothing Then
    				Return False
    			Else
    				Return True
    			End If
    		End Get
    
    		Set(ByVal Value As Boolean)
    			ViewState("Debug_Mode") = Value
    		End Set
    
    	End Property


    Monday, July 27, 2009 8:12 PM
  • User1780761961 posted

    Thanks jkirkerx but I don't think that's it. I need the double quotes to specify the key value for ViewState i.e. the property name and not its value.

    I have managed to get the controls to render correctly but have had to change the implementation from a seperate class library project to a local class within the aspx project i.e.

    Originally I had created my controls in a seperate class library project "CustomServerControls". I add this project as a reference to my main aspx project and added the following to web.config:

       <pages validateRequest="True" maintainScrollPositionOnPostBack="true">
          <controls>
            <add tagPrefix="csc" namespace="CustomServerControls" assembly="CustomServerControls"/>
          </controls>

        </pages>

    I think this is the standard practise e.g. to allow the controls to be added to the toolbar etc.

    By changing to using a local class in App_Code of my aspx project and adding the following page directive:

    <%@ Register TagPrefix="occ" Namespace="OBSCustomControls" %>

    the control renders without issue.

    Naturally my preference is to use a seperate class library, any advise on how to correct is greatly appreciated.
     

    Regards,

    Harj

    Tuesday, July 28, 2009 4:30 AM
  • User-2106054853 posted

     Hi,

    It looks like an IDE issue. Please submit a feedback to https://connect.microsoft.com/VisualStudio. Our dedicated engineers will work with you on this issue.

    The root cause is probably dll mismatch in the following folder:

    C:\Users\yourusername\AppData\Local\Microsoft\VisualStudio\9.0\ProjectAssemblies

    More information:

     

    0:000> !printexception
    Exception object: 04310cfc
    Exception type: System.InvalidCastException
    Message: [A]WebApplication2.TestTextBox cannot be cast to [B]WebApplication2.TestTextBox. Type A originates from 'WebApplication2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location 'C:\Users\allenc\AppData\Local\Microsoft\VisualStudio\9.0\ProjectAssemblies\d_kkawks01\WebApplication2.DLL'. Type B originates from 'WebApplication2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadNeither' at location 'C:\Users\allenc\AppData\Local\Microsoft\VisualStudio\9.0\ProjectAssemblies\lnh3lpju01\webapplication2.dll'.
    InnerException: <none>
    StackTrace (generated):
    <none>
    StackTraceString: <none>
    HResult: 80004002


    0:000> !clrstack
    OS Thread Id: 0x322c (0)
    ESP       EIP    
    002de7e8 75bef35f [HelperMethodFrame_1OBJ: 002de7e8]
    002de848 0ec865e6 Unknown MethodDesc (Module 14aad248, mdToken 0600000b)
    002de858 0c7676c8 System.Web.Util.FastPropertyAccessor.SetProperty(System.Object, System.String, System.Object)
    002de86c 0c766375 System.Web.UI.PropertyMapper.SetMappedPropertyValue(System.Object, System.String, System.Object)
    002de87c 0c6a2ccf System.Web.UI.ControlBuilder.SetSimpleProperty(System.Web.UI.SimplePropertyEntry, System.Object)
    002de8ac 0c6a2c12 System.Web.UI.ControlBuilder.InitSimpleProperties(System.Object)
    002de8d8 0c6a2a97 System.Web.UI.ControlBuilder.InitObject(System.Object)
    002de8f0 0c6a247f System.Web.UI.ControlBuilder.BuildObjectInternal()
    002de904 0c6a2315 System.Web.UI.ControlBuilder.BuildObject()
    002de908 0c6a2381 System.Web.UI.ControlBuilder.BuildObject(Boolean)
    002de91c 0c774221 System.Web.UI.DesignTimeTemplateParser.ParseControlsInternal(System.Web.UI.DesignTimeParseData, Boolean)
    002de960 0c774409 System.Web.UI.DesignTimeTemplateParser.ParseControl(System.Web.UI.DesignTimeParseData)
    002de968 50e1935b System.Web.UI.Design.ControlSerializer.DeserializeControlInternal(System.String, System.ComponentModel.Design.IDesignerHost, Boolean)
    002de9a0 50e16960 System.Web.UI.Design.ControlParser.ParseControl(System.ComponentModel.Design.IDesignerHost, System.String, Boolean)
    002de9b8 50e12271 System.Web.UI.Design.ControlDesigner.CreateClonedControl(System.ComponentModel.Design.IDesignerHost, Boolean)
    002de9d4 50e11e65 System.Web.UI.Design.ControlDesigner.CreateViewControl()
    002de9e4 50e11ec3 System.Web.UI.Design.ControlDesigner.CreateViewControlInternal()
    002de9fc 50e12515 System.Web.UI.Design.ControlDesigner.get_ViewControl()
    002dea10 50e13004 System.Web.UI.Design.ControlDesigner.GetDesignTimeHtml()
    002dea50 50e130f7 System.Web.UI.Design.ControlDesigner.GetDesignTimeHtml(System.Web.UI.Design.DesignerRegionCollection)
    002dea60 50e14995 System.Web.UI.Design.ControlDesigner.GetViewRendering(System.Web.UI.Design.ControlDesigner)
    002dea9c 50e14aa6 System.Web.UI.Design.ControlDesigner.GetViewRendering()
    002deab0 0f58ec84 Microsoft.Web.Design.ElementDesigner.UpdateView(Boolean)
    002deae8 0b2663f2 Microsoft.Web.Design.ElementDesigner.System.Web.UI.Design.IControlDesignerView.Update()
    002deaec 50e138dc System.Web.UI.Design.ControlDesigner.UpdateDesignTimeHtml()
    002deb00 50e144bf System.Web.UI.Design.ControlDesigner.OnComponentChanged(System.Object, System.ComponentModel.Design.ComponentChangedEventArgs)
    002deb4c 0b266362 Microsoft.Web.Design.DocumentDesigner.OnComponentChanged(System.Object, System.ComponentModel.Design.ComponentChangedEventArgs)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 29, 2009 4:51 AM