Getting error "Unable to generate code for a value of type"

Discussion in 'ASP .Net Building Controls' started by xyz, Jul 3, 2003.

  1. xyz

    xyz Guest

    I have created a server control for asp.net using C#. Everything works fine
    in Visual Studio, but when I attempt to look at the page I get an error.
    Below is my code and the error. Can anybody help me determine the problem
    and how I can resolve it. Thanks.

    using System;

    using System.ComponentModel;

    using System.Globalization;

    namespace LCOGTools_WebForms_SrchRcrd

    {

    /// <summary>

    /// Summary description for PersonStructure.

    /// </summary>

    public class LCOGCntrlSrchRcrd

    {

    private string srchCntrlNm = "";

    private string srchFldNm = "";

    private string srchTblNm = "";


    [

    DescriptionAttribute ("Web form control this relates to.")

    , NotifyParentPropertyAttribute (true)

    , RefreshPropertiesAttribute (System.ComponentModel.RefreshProperties.All)

    , BindableAttribute (System.ComponentModel.BindableSupport.Yes)

    ]

    public string SrchCntrlNm

    {

    get

    {

    return srchCntrlNm;

    }

    set

    {

    this.srchCntrlNm = value;

    }

    }

    [

    DescriptionAttribute ("Database table field this control relates to.")

    , NotifyParentPropertyAttribute (true)

    , RefreshPropertiesAttribute (System.ComponentModel.RefreshProperties.All)

    , BindableAttribute (System.ComponentModel.BindableSupport.Yes)

    ]

    public string SrchFldNm

    {

    get

    {

    return srchFldNm;

    }

    set

    {

    this.srchFldNm = value;

    }

    }

    [

    DescriptionAttribute ("Database table this control relates to.")

    , NotifyParentPropertyAttribute (true)

    , RefreshPropertiesAttribute (System.ComponentModel.RefreshProperties.All)

    , BindableAttribute (System.ComponentModel.BindableSupport.Yes)

    ]

    public string SrchTblNm

    {

    get

    {

    return srchTblNm;

    }

    set

    {

    this.srchTblNm = value;

    }

    }

    public override string ToString ()

    {

    string ls_ToString;

    ls_ToString =

    "srchCntrlNm==" + this.srchCntrlNm

    + "srchTblNm==" + this.srchTblNm

    + "srchFldNm==" + this.srchFldNm

    ;

    return ls_ToString;

    }

    }

    public class LCOGCntrlSrchRcrdConverter : ExpandableObjectConverter

    {

    public override bool CanConvertFrom (ITypeDescriptorContext context, Type t)

    {

    if (t == typeof(string))

    {

    return true;

    }

    return base.CanConvertFrom(context, t);

    }

    public override object ConvertFrom (ITypeDescriptorContext context,
    CultureInfo info, object value)

    {

    LCOGCntrlSrchRcrd lo_CurrSrchRcrd = new LCOGCntrlSrchRcrd ();

    int li_CommaPos;

    string ls_ValueIn;

    string ls_WorkValue;

    // Here you can parse things to get the data out there that you want.

    if (value is string)

    {

    try

    {

    ls_ValueIn = (string) value;

    ls_WorkValue = ls_ValueIn;

    // Parse the format of srchCntrlNm,srchTblNm,srchFldNm

    // Get SrchCntrlNm

    li_CommaPos = ls_WorkValue.IndexOf (",");

    if (li_CommaPos != -1)

    {

    lo_CurrSrchRcrd.SrchCntrlNm = ls_WorkValue.Substring (0, li_CommaPos);

    ls_WorkValue = ls_WorkValue.Substring ((li_CommaPos+1));

    } // End of if (li_CommaPos != -1).

    // Get SrchFldNm

    li_CommaPos = ls_WorkValue.IndexOf (",");

    if (li_CommaPos != -1)

    {

    lo_CurrSrchRcrd.SrchFldNm = ls_WorkValue.Substring (0, li_CommaPos);

    ls_WorkValue = ls_WorkValue.Substring ((li_CommaPos+1));

    } // End of if (li_CommaPos != -1).

    // Get SrchTblNm

    li_CommaPos = ls_WorkValue.IndexOf (",");

    lo_CurrSrchRcrd.SrchTblNm = ls_WorkValue;

    // Return this record to the caller.

    return (lo_CurrSrchRcrd);

    } // End of try.

    catch

    {

    }

    // If we got this far, complain that we could not parse the string.

    throw new ArgumentException ("Can not convert '"

    + (string) value + "' to type LCOG Control Search Record");

    } // End of if (value is string).

    return base.ConvertFrom (context, info, value);

    }

    public override object ConvertTo (ITypeDescriptorContext context,
    CultureInfo culture, object value, Type destType)

    {

    if (destType == typeof(string) && value is LCOGCntrlSrchRcrd)

    {

    string ls_ConvertToValue = "";

    LCOGCntrlSrchRcrd lo_CurrSrchRcrd = (LCOGCntrlSrchRcrd) value;

    if ((lo_CurrSrchRcrd.SrchCntrlNm != "") && (lo_CurrSrchRcrd.SrchCntrlNm !=
    null))

    {

    ls_ConvertToValue = lo_CurrSrchRcrd.SrchCntrlNm + "," +
    lo_CurrSrchRcrd.SrchFldNm + "," + lo_CurrSrchRcrd.SrchTblNm;

    }

    return ls_ConvertToValue;

    }

    return base.ConvertTo(context, culture, value, destType);

    }

    }

    }






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

    Unable to generate code for a value of type
    'LCOGTools_WebForms_SrchRcrd.LCOGCntrlSrchRcrd'. This error occurred while
    trying to generate the property value for SearchControl.
    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.Web.HttpException: Unable to generate code for a
    value of type 'LCOGTools_WebForms_SrchRcrd.LCOGCntrlSrchRcrd'. This error
    occurred while trying to generate the property value for SearchControl.

    Source Error:

    An unhandled exception was generated during the execution of the
    current web request. Information regarding the origin and location of the
    exception can be identified using the exception stack trace below.

    Stack Trace:

    [HttpException (0x80004005): Unable to generate code for a value of type
    'LCOGTools_WebForms_SrchRcrd.LCOGCntrlSrchRcrd'. This error occurred while
    trying to generate the property value for SearchControl.]

    System.Web.Compilation.CodeDomUtility.GenerateExpressionForValue(PropertyInf
    o propertyInfo, Object value, Type valueType) +2253

    System.Web.Compilation.TemplateControlCompiler.BuildBuildMethod(ControlBuild
    er builder, Boolean fTemplate, PropertySetterEntry pse) +2538

    System.Web.Compilation.TemplateControlCompiler.BuildSourceDataTreeFromBuilde
    r(ControlBuilder builder, Boolean fInTemplate, PropertySetterEntry pse) +794

    System.Web.Compilation.TemplateControlCompiler.BuildSourceDataTreeFromBuilde
    r(ControlBuilder builder, Boolean fInTemplate, PropertySetterEntry pse) +352

    System.Web.Compilation.TemplateControlCompiler.BuildSourceDataTreeFromBuilde
    r(ControlBuilder builder, Boolean fInTemplate, PropertySetterEntry pse) +352
    System.Web.Compilation.TemplateControlCompiler.BuildMiscClassMembers()
    +51
    System.Web.Compilation.PageCompiler.BuildMiscClassMembers() +10
    System.Web.Compilation.BaseCompiler.BuildSourceDataTree() +1276
    System.Web.Compilation.BaseCompiler.GetCompiledType() +129
    System.Web.UI.PageParser.CompileIntoType() +59
    System.Web.UI.TemplateParser.GetParserCacheItemThroughCompilation() +126

    [HttpException (0x80004005): Unable to generate code for a value of type
    'LCOGTools_WebForms_SrchRcrd.LCOGCntrlSrchRcrd'. This error occurred while
    trying to generate the property value for SearchControl.]
    System.Web.UI.TemplateParser.GetParserCacheItemInternal(Boolean
    fCreateIfNotFound) +692
    System.Web.UI.TemplateParser.GetParserCacheItemWithNewConfigPath() +125
    System.Web.UI.TemplateParser.GetParserCacheItem() +88
    System.Web.UI.TemplateControlParser.CompileAndGetParserCacheItem(String
    virtualPath, String inputFile, HttpContext context) +116
    System.Web.UI.TemplateControlParser.GetCompiledInstance(String
    virtualPath, String inputFile, HttpContext context) +36
    System.Web.UI.PageParser.GetCompiledPageInstanceInternal(String
    virtualPath, String inputFile, HttpContext context) +43
    System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String
    requestType, String url, String path) +44
    System.Web.HttpApplication.MapHttpHandler(HttpContext context, String
    requestType, String path, String pathTranslated, Boolean useAppConfig) +699

    System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep
    ..Execute() +95
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
    completedSynchronously) +173



    ----------------------------------------------------------------------------
    ----
    Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET
    Version:1.1.4322.573
    xyz, Jul 3, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Bower
    Replies:
    4
    Views:
    1,606
    Chris Bower
    Nov 18, 2003
  2. juvi
    Replies:
    3
    Views:
    1,035
    Alexey Smirnov
    Jan 22, 2009
  3. Chris Bower

    Unable to generate code for a value of type...

    Chris Bower, Nov 17, 2003, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    237
    Chris Bower
    Nov 18, 2003
  4. KMILO
    Replies:
    0
    Views:
    153
    KMILO
    Apr 25, 2005
  5. George
    Replies:
    4
    Views:
    584
    Roedy Green
    Jun 28, 2012
Loading...

Share This Page