CodeSmith Community
Your Code. Your Way. Faster!

Error in Filter.cs

Latest post 12-12-2006 1:31 PM by enijburg. 6 replies.
  • 10-12-2006 9:06 AM

    Error in Filter.cs

    I believe the value is null or empty string and the file should check for this.

    -Chris

    -------

    Index and length must refer to a location within the string.
    Parameter name: length

    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.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
    Parameter name: length

    Source Error:

    Line 560:		private string CorrectUserValue(string UserValue)
    Line 561:		{
    Line 562:			if (UserValue.Substring(0,1)  == "'")
    Line 563:			{
    Line 564:				UserValue =UserValue.Replace("'", "");

    Source File: C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-11\YourCompany.One.Entities\Filter.cs    Line: 562

    Stack Trace:

    [ArgumentOutOfRangeException: Index and length must refer to a location within the string.
    Parameter name: length]
       System.String.InternalSubStringWithChecks(Int32 startIndex, Int32 length, Boolean fAlwaysCopy) +2848599
       System.String.Substring(Int32 startIndex, Int32 length) +11
       YourCompany.One.Entities.Filter`2.CorrectUserValue(String UserValue) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-11\YourCompany.One.Entities\Filter.cs:562
       YourCompany.One.Entities.Filter`2.IsOk(Object ObjectPropertyValue, String Operator, String UserValue) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-11\YourCompany.One.Entities\Filter.cs:594
       YourCompany.One.Entities.Filter`2.ApplyFilter(T ObjectToFilter, String StrFilter) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-11\YourCompany.One.Entities\Filter.cs:694
       YourCompany.One.Entities.Filter`2..ctor(T objToFilter, String filter) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-11\YourCompany.One.Entities\Filter.cs:188
       YourCompany.One.Entities.ListBase`1.ApplyFilter() in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-11\YourCompany.One.Entities\ListBase.cs:412
       YourCompany.One.Entities.ListBase`1.set_Filter(String value) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-11\YourCompany.One.Entities\ListBase.cs:236
    
    [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) +358
       System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
       System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) +96
       System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index) +24
       YourCompany.One.Entities.EntityUtil.SetPropertyValue(Object item, String propertyName, Object propertyValue, PropertyInfo& property, Boolean convertBlankToNull) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-11\YourCompany.One.Entities\EntityUtil.cs:378
       YourCompany.One.Entities.EntityUtil.SetPropertyValue(Object item, String propertyName, Object propertyValue, Boolean convertBlankToNull) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-11\YourCompany.One.Entities\EntityUtil.cs:348
       YourCompany.One.Entities.EntityUtil.SetPropertyValue(Object item, String propertyName, Object propertyValue) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-11\YourCompany.One.Entities\EntityUtil.cs:335
       YourCompany.One.Web.Data.EntityDataSourceFilterView.ExecuteSelect(DataSourceSelectArguments arguments) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-11\YourCompany.One.Web\Data\EntityDataSourceFilter.cs:239
       System.Web.UI.WebControls.Repeater.GetData() +50
       System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +232
       System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +53
       System.Web.UI.WebControls.Repeater.DataBind() +72
       System.Web.UI.WebControls.Repeater.EnsureDataBound() +55
       System.Web.UI.WebControls.Repeater.OnPreRender(EventArgs e) +12
       System.Web.UI.Control.PreRenderRecursiveInternal() +77
       System.Web.UI.Control.PreRenderRecursiveInternal() +161
       System.Web.UI.Control.PreRenderRecursiveInternal() +161
       System.Web.UI.Control.PreRenderRecursiveInternal() +161
       System.Web.UI.Control.PreRenderRecursiveInternal() +161
       System.Web.UI.Control.PreRenderRecursiveInternal() +161
       System.Web.UI.Control.PreRenderRecursiveInternal() +161
       System.Web.UI.Control.PreRenderRecursiveInternal() +161
       System.Web.UI.Control.PreRenderRecursiveInternal() +161
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1360
    


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


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

    • Post Points: 45
  • 10-13-2006 12:55 AM In reply to

    • GBR
    • Top 500 Contributor
    • Joined on 11-28-2005
    • Posts 17
    • Points 530

    Re: Error in Filter.cs

    Hi,

     I ran into the same issue when using the Generated Admin Website.  I found that whenever a Foreign Key column had a record with a null it broke the page that displayed the Grid.  i.e. it is expecting all foreign-key values to be populated.  I've not had a chance to investigate yet...

    Not sure this will help ... but maybe it will. 

    I'm using .netTiers v2.0.0.387

     -GBR

    I'm using .netTiers v2.0.0.387

     -GBR

    • Post Points: 35
  • 10-13-2006 1:42 AM In reply to

    Re: Error in Filter.cs

    Fixed In Rev 418


    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    • Post Points: 35
  • 10-13-2006 10:54 AM In reply to

    Re: Error in Filter.cs

    Not fixed. See Error in EntityUtil.cs
    • Post Points: 5
  • 10-13-2006 5:38 PM In reply to

    Re: Error in Filter.cs

    FYI:  After getting into right SVN folder (@ revision 421) Still also get Error in EntityUtil.cs

    Error at line 605 in Filter.cs

    Input string was not in a correct format.

    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.FormatException: Input string was not in a correct format.

    Source Error:

    Line 603:			else if (TypeOfValue ==typeof(int))
    Line 604:			{
    Line 605:				Rt = IsOk((int)ObjectPropertyValue, Operator, (int) Convert.ToInt32(FilterValue));
    Line 606:			}
    Line 607:			else if (TypeOfValue == typeof(double))

    Source File: C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-13\YourCompany.One.Entities\Filter.cs    Line: 605

    Stack Trace:

    [FormatException: Input string was not in a correct format.]
       System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2753507
       System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +102
       System.String.System.IConvertible.ToInt32(IFormatProvider provider) +43
       System.Convert.ToInt32(Object value) +25
       YourCompany.One.Entities.Filter`2.IsOk(Object ObjectPropertyValue, String Operator, String UserValue) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-13\YourCompany.One.Entities\Filter.cs:605
       YourCompany.One.Entities.Filter`2.ApplyFilter(T ObjectToFilter, String StrFilter) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-13\YourCompany.One.Entities\Filter.cs:697
       YourCompany.One.Entities.Filter`2..ctor(T objToFilter, String filter) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-13\YourCompany.One.Entities\Filter.cs:188
       YourCompany.One.Entities.ListBase`1.ApplyFilter() in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-13\YourCompany.One.Entities\ListBase.cs:412
       YourCompany.One.Entities.ListBase`1.set_Filter(String value) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-13\YourCompany.One.Entities\ListBase.cs:236
    
    [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) +358
       System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +29
       System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture) +96
       System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index) +24
       YourCompany.One.Entities.EntityUtil.SetPropertyValue(Object item, String propertyName, Object propertyValue, PropertyInfo& property, Boolean convertBlankToNull) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-13\YourCompany.One.Entities\EntityUtil.cs:378
       YourCompany.One.Entities.EntityUtil.SetPropertyValue(Object item, String propertyName, Object propertyValue, Boolean convertBlankToNull) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-13\YourCompany.One.Entities\EntityUtil.cs:348
       YourCompany.One.Entities.EntityUtil.SetPropertyValue(Object item, String propertyName, Object propertyValue) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-13\YourCompany.One.Entities\EntityUtil.cs:335
       YourCompany.One.Web.Data.EntityDataSourceFilterView.ExecuteSelect(DataSourceSelectArguments arguments) in C:\Documents and Settings\user\My Documents\YourCompany\NetTiers\2006-10-13\YourCompany.One.Web\Data\EntityDataSourceFilter.cs:239
       System.Web.UI.WebControls.Repeater.GetData() +57
       System.Web.UI.WebControls.Repeater.CreateControlHierarchy(Boolean useDataSource) +292
       System.Web.UI.WebControls.Repeater.OnDataBinding(EventArgs e) +71
       System.Web.UI.WebControls.Repeater.DataBind() +85
       System.Web.UI.WebControls.Repeater.EnsureDataBound() +83
       System.Web.UI.WebControls.Repeater.OnPreRender(EventArgs e) +27
       System.Web.UI.Control.PreRenderRecursiveInternal() +148
       System.Web.UI.Control.PreRenderRecursiveInternal() +233
       System.Web.UI.Control.PreRenderRecursiveInternal() +233
       System.Web.UI.Control.PreRenderRecursiveInternal() +233
       System.Web.UI.Control.PreRenderRecursiveInternal() +233
       System.Web.UI.Control.PreRenderRecursiveInternal() +233
       System.Web.UI.Control.PreRenderRecursiveInternal() +233
       System.Web.UI.Control.PreRenderRecursiveInternal() +233
       System.Web.UI.Control.PreRenderRecursiveInternal() +233
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4436
    


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


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


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

    • Post Points: 5
  • 10-16-2006 9:40 AM In reply to

    Re: Error in Filter.cs

    I added the below code to line 605 of Filter.cs in the private bool IsOk(object ObjectPropertyValue , string Operator, string UserValue) method. This fix seems to stop this error and also fix the error in post "Error IdentityField no displaying data ". I'm not sure if or what the ramifications of this fix would be.

     -Chris

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

    if (FilterValue.ToString() != String.Empty)

    Rt = IsOk((int)ObjectPropertyValue, Operator, (int) Convert.ToInt32(FilterValue));

    if (FilterValue.ToString() != String.Empty)

    Rt = IsOk((int)ObjectPropertyValue, Operator, (int) Convert.ToInt32(FilterValue));

    int)ObjectPropertyValue, Operator, (int) Convert.ToInt32(FilterValue));

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

    • Post Points: 35
  • 12-12-2006 1:31 PM In reply to

    • enijburg
    • Top 500 Contributor
    • Joined on 10-03-2006
    • Posts 9
    • Points 165

    Re: Error in Filter.cs

    Your construct would mean that the <> and != operators would fail as well. (n <> '' and n != '' should be valid).

    I've used the following workaround, but IMO a more stable fix has to be devised.

    if (UserValue != "")

    {

    if (TypeOfValue == typeof(int))

    {

      Rt = IsOk((int)ObjectPropertyValue, Operator, (int)Convert.ToInt32(FilterValue));

    }

    else if (TypeOfValue == typeof(double))

    {

      Rt = IsOk((double)ObjectPropertyValue, Operator, (double)Convert.ToDouble(FilterValue));

    }

    else if (TypeOfValue == typeof(decimal))

    {

      Rt = IsOk((decimal)ObjectPropertyValue, Operator, (decimal)Convert.ToDecimal(FilterValue));

    }

    else if (TypeOfValue == typeof(DateTime))

    {

      Rt = IsOk((DateTime)ObjectPropertyValue, Operator, (DateTime)Convert.ToDateTime(FilterValue));

    }

    else if (TypeOfValue == typeof(bool))

    {

      Rt = IsOk((bool)ObjectPropertyValue, Operator, (bool)Convert.ToBoolean(FilterValue));

    }

    else if (TypeOfValue == typeof(Guid))

    {

      Rt = IsOk((Guid)ObjectPropertyValue, Operator, new Guid(FilterValue.ToString()));

    }

    else if (TypeOfValue == typeof(decimal))

    {

      Rt = IsOk((decimal)ObjectPropertyValue, Operator, (decimal)Convert.ToDecimal(FilterValue));

    }

    else if (TypeOfValue == typeof(byte))

    {

      Rt = IsOk((byte)ObjectPropertyValue, Operator, (byte)Convert.ToByte(FilterValue));

    }

    else if (TypeOfValue == typeof(long))

    {

      Rt = IsOk((long)ObjectPropertyValue, Operator, (long)Convert.ToInt64(FilterValue));

    }

    else if (TypeOfValue == typeof(System.Int16))

    {

      Rt = IsOk((System.Int16)ObjectPropertyValue, Operator, (System.Int16)Convert.ToInt16(FilterValue));

    }

    else

    {

      throw new Exception("Filtering is not possible on the type " + TypeOfValue.ToString());

    }

    }

    else

    {

    // FilterValue is empty, conversion would lead to errors. Treat as string

    Rt = IsOk(ObjectPropertyValue.ToString(), Operator, FilterValue.ToString());

    }

     

    Regards,
    Ewart

     

    • Post Points: 5
Page 1 of 1 (7 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems