locked
Custom Extension Methods and Dynamic LINQ (Dynamic Expression API)

    Question

  • Hello all,

    I have the following string I'd like to evaluate as LINQ:

    (linq query).Where("sbc.CompanyName.Equals(\"hello%20world\".UrlDecode())")
    
    

    UrlDecode is an extension method that I wrote:

    public static class StringExtension
    {
    	public static String UrlDecode(this String s)
    	{
    
     		return HttpUtility.UrlDecode(s);
    
    	}
    
    }
    
    
    

     

    but when evaluated I get the error:

     

    No applicable method 'UrlDecode' exists in type 'String'

    In Dynamic.cs, FindMethod is not finding my extension method when it calls String.FindMembers

    I'm relatively new to Dynamic LINQ and extension methods, can anyone assist?

    Many thanks,

    Brad

     

    Wednesday, September 01, 2010 8:13 PM

Answers

  • Hello Brad,

     

    Welcome to EF forum!

     

    Extension method is quite different from normal method.  As we seen in C# codes, extension method are defined as static methods even they are called by using instance method syntax.   The first parameter specifies which type the method operates on.   So when using .NET Reflection to find the MethodInfo of extension methods, we need to search the static class which holds the extension methods instead of finding it at the type (the first parameter) which extension method reply on. 

     

    Therefore, in your scenario, it’s really hard to make the extension method be called dynamically since these methods can be found in any possible static classes.  

     

    Of course, we can manually use .NET Reflection to find the method in certain hardcoded static classes and dynamically call them as a regular static method.  REMEMBER:  the instance type should be the first parameter of the extension method.

     

    Good day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, September 02, 2010 9:27 AM
  • Ok figured that out, had to add typeof(StringExtension) to the predefinedTypes array. Now I'm getting:

     

    System.ArgumentException: Incorrect number of arguments supplied for call to method 'System.String UrlDecode(System.String)'
      at System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodInfo method, ReadOnlyCollection`1& arguments)
      at System.Linq.Expressions.Expression.ValidateCallArgs(Expression instance, MethodInfo method, ReadOnlyCollection`1& arguments)
      at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
      at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression[] arguments)
      at System.Linq.Dynamic.ExpressionParser.ParseMemberAccess(Type type, Expression instance) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 1294
      at System.Linq.Dynamic.ExpressionParser.ParsePrimary() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 960
      at System.Linq.Dynamic.ExpressionParser.ParseUnary() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 949
      at System.Linq.Dynamic.ExpressionParser.ParseMultiplicative() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 896
      at System.Linq.Dynamic.ExpressionParser.ParseAdditive() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 866
      at System.Linq.Dynamic.ExpressionParser.ParseComparison() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 783
      at System.Linq.Dynamic.ExpressionParser.ParseLogicalAnd() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 768
      at System.Linq.Dynamic.ExpressionParser.ParseLogicalOr() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 753
      at System.Linq.Dynamic.ExpressionParser.ParseExpression() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 737
      at System.Linq.Dynamic.ExpressionParser.ParseArguments() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 1375
      at System.Linq.Dynamic.ExpressionParser.ParseArgumentList() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 1364
      at System.Linq.Dynamic.ExpressionParser.ParseMemberAccess(Type type, Expression instance) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 1280
      at System.Linq.Dynamic.ExpressionParser.ParsePrimary() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 960
      at System.Linq.Dynamic.ExpressionParser.ParseUnary() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 949
      at System.Linq.Dynamic.ExpressionParser.ParseMultiplicative() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 896
      at System.Linq.Dynamic.ExpressionParser.ParseAdditive() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 866
      at System.Linq.Dynamic.ExpressionParser.ParseComparison() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 783
      at System.Linq.Dynamic.ExpressionParser.ParseLogicalAnd() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 768
      at System.Linq.Dynamic.ExpressionParser.ParseLogicalOr() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 753
      at System.Linq.Dynamic.ExpressionParser.ParseExpression() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 737
      at System.Linq.Dynamic.ExpressionParser.ParseParenExpression() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 1076
      at System.Linq.Dynamic.ExpressionParser.ParsePrimaryStart() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 987
      at System.Linq.Dynamic.ExpressionParser.ParsePrimary() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 954
      at System.Linq.Dynamic.ExpressionParser.ParseUnary() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 949
      at System.Linq.Dynamic.ExpressionParser.ParseMultiplicative() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 896
      at System.Linq.Dynamic.ExpressionParser.ParseAdditive() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 866
      at System.Linq.Dynamic.ExpressionParser.ParseComparison() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 783
      at System.Linq.Dynamic.ExpressionParser.ParseLogicalAnd() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 768
      at System.Linq.Dynamic.ExpressionParser.ParseLogicalOr() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 753
      at System.Linq.Dynamic.ExpressionParser.ParseExpression() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 737
      at System.Linq.Dynamic.ExpressionParser.Parse(Type resultType) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 699
      at System.Linq.Dynamic.DynamicExpression.ParseLambda(ParameterExpression[] parameters, Type resultType, String expression, Object[] values) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 195
      at System.Linq.Dynamic.DynamicExpression.ParseLambda(Type itType, Type resultType, String expression, Object[] values) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 189
      at System.Linq.Dynamic.DynamicQueryable.Where(IQueryable source, String predicate, Object[] values) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 35
      at System.Linq.Dynamic.DynamicQueryable.Where[T](IQueryable`1 source, String predicate, Object[] values) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 28
      at IRR_Reporting_Core_Lib.ExpansionMethods.GroupCalc(String groupbyval, String whereclause) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\ExpansionMethods.cs:line 96
      at IRR_Reporting_Core_Lib.ReportCalc.GetExpandedData() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Calc.cs:line 302
      at IRR_Reporting.MainView.ExpandByParameter() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting\IRR_Reporting\IRR_Reporting\MainView.cs:line 3042
    

    Which occurs at the following code:

     

    return Expression.Call(instance, (MethodInfo)method, args);
    

    Where instance is the UrlEncoded string, method is my static UrlDecode method, and args is System.Linq.Expressions.Expression[0]. I'm a litte lost on this but I'll keep digging - if you have any ideas please let me know - thank you!

    Brad

    Thursday, September 02, 2010 4:02 PM
  • Ok I figured it out - stop tried using UrlDecode as an extension method and just made a normal method call in the dynamic LINQ syntax. That worked! thanks!
    Thursday, September 02, 2010 8:02 PM

All replies

  • Hello Brad,

     

    Welcome to EF forum!

     

    Extension method is quite different from normal method.  As we seen in C# codes, extension method are defined as static methods even they are called by using instance method syntax.   The first parameter specifies which type the method operates on.   So when using .NET Reflection to find the MethodInfo of extension methods, we need to search the static class which holds the extension methods instead of finding it at the type (the first parameter) which extension method reply on. 

     

    Therefore, in your scenario, it’s really hard to make the extension method be called dynamically since these methods can be found in any possible static classes.  

     

    Of course, we can manually use .NET Reflection to find the method in certain hardcoded static classes and dynamically call them as a regular static method.  REMEMBER:  the instance type should be the first parameter of the extension method.

     

    Good day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, September 02, 2010 9:27 AM
  • Hi Lingzi!

    Thanks so much for your reply, I had a feeling I was over-simplifying things. Ok so I'm trying to understand how to implement this in Dynamic.cs, but I'm running into another problem. I have modified FindMethod to the following:

    int FindMethod(Type type, string methodName, bool staticAccess, Expression[] args, out MethodBase method)
        {
          if (methodName == "UrlDecode")
          {
            method = typeof(StringExtension)
                  .GetMethods(
                          BindingFlags.Public |
                          BindingFlags.Static
                        )
                   .Where(o => o.Name == "UrlDecode").First();
    
            return 1;
    
          }
          BindingFlags flags = BindingFlags.Public | BindingFlags.DeclaredOnly |
            (staticAccess ? BindingFlags.Static : BindingFlags.Instance);
          foreach (Type t in SelfAndBaseTypes(type))
          {
            MemberInfo[] members = t.FindMembers(MemberTypes.Method,
              flags, Type.FilterNameIgnoreCase, methodName);
            int count = FindBestMethod(members.Cast<MethodBase>(), args, out method);
            if (count != 0) return count;
          }
          method = null;
          return 0;
        }
    

    And added the following class to Dynamic.cs within the System.Linq.Dynamic namespace:

    static class StringExtension
      {
        public static string UrlDecode(string s)
        {
          return System.Web.HttpUtility.UrlDecode(s);
        }
      }
    

    When executing Dynamic LINQ with something like "%20test%20".UrlDecode(), I get the following error message:

    "Methods on type 'StringExtension' are not accessible"

    Can you please shed any light on what I am doing incorrectly? Thanks again, Brad

    Thursday, September 02, 2010 1:45 PM
  • Ok figured that out, had to add typeof(StringExtension) to the predefinedTypes array. Now I'm getting:

     

    System.ArgumentException: Incorrect number of arguments supplied for call to method 'System.String UrlDecode(System.String)'
      at System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodInfo method, ReadOnlyCollection`1& arguments)
      at System.Linq.Expressions.Expression.ValidateCallArgs(Expression instance, MethodInfo method, ReadOnlyCollection`1& arguments)
      at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)
      at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, Expression[] arguments)
      at System.Linq.Dynamic.ExpressionParser.ParseMemberAccess(Type type, Expression instance) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 1294
      at System.Linq.Dynamic.ExpressionParser.ParsePrimary() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 960
      at System.Linq.Dynamic.ExpressionParser.ParseUnary() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 949
      at System.Linq.Dynamic.ExpressionParser.ParseMultiplicative() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 896
      at System.Linq.Dynamic.ExpressionParser.ParseAdditive() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 866
      at System.Linq.Dynamic.ExpressionParser.ParseComparison() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 783
      at System.Linq.Dynamic.ExpressionParser.ParseLogicalAnd() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 768
      at System.Linq.Dynamic.ExpressionParser.ParseLogicalOr() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 753
      at System.Linq.Dynamic.ExpressionParser.ParseExpression() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 737
      at System.Linq.Dynamic.ExpressionParser.ParseArguments() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 1375
      at System.Linq.Dynamic.ExpressionParser.ParseArgumentList() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 1364
      at System.Linq.Dynamic.ExpressionParser.ParseMemberAccess(Type type, Expression instance) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 1280
      at System.Linq.Dynamic.ExpressionParser.ParsePrimary() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 960
      at System.Linq.Dynamic.ExpressionParser.ParseUnary() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 949
      at System.Linq.Dynamic.ExpressionParser.ParseMultiplicative() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 896
      at System.Linq.Dynamic.ExpressionParser.ParseAdditive() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 866
      at System.Linq.Dynamic.ExpressionParser.ParseComparison() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 783
      at System.Linq.Dynamic.ExpressionParser.ParseLogicalAnd() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 768
      at System.Linq.Dynamic.ExpressionParser.ParseLogicalOr() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 753
      at System.Linq.Dynamic.ExpressionParser.ParseExpression() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 737
      at System.Linq.Dynamic.ExpressionParser.ParseParenExpression() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 1076
      at System.Linq.Dynamic.ExpressionParser.ParsePrimaryStart() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 987
      at System.Linq.Dynamic.ExpressionParser.ParsePrimary() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 954
      at System.Linq.Dynamic.ExpressionParser.ParseUnary() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 949
      at System.Linq.Dynamic.ExpressionParser.ParseMultiplicative() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 896
      at System.Linq.Dynamic.ExpressionParser.ParseAdditive() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 866
      at System.Linq.Dynamic.ExpressionParser.ParseComparison() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 783
      at System.Linq.Dynamic.ExpressionParser.ParseLogicalAnd() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 768
      at System.Linq.Dynamic.ExpressionParser.ParseLogicalOr() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 753
      at System.Linq.Dynamic.ExpressionParser.ParseExpression() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 737
      at System.Linq.Dynamic.ExpressionParser.Parse(Type resultType) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 699
      at System.Linq.Dynamic.DynamicExpression.ParseLambda(ParameterExpression[] parameters, Type resultType, String expression, Object[] values) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 195
      at System.Linq.Dynamic.DynamicExpression.ParseLambda(Type itType, Type resultType, String expression, Object[] values) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 189
      at System.Linq.Dynamic.DynamicQueryable.Where(IQueryable source, String predicate, Object[] values) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 35
      at System.Linq.Dynamic.DynamicQueryable.Where[T](IQueryable`1 source, String predicate, Object[] values) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Dynamic.cs:line 28
      at IRR_Reporting_Core_Lib.ExpansionMethods.GroupCalc(String groupbyval, String whereclause) in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\ExpansionMethods.cs:line 96
      at IRR_Reporting_Core_Lib.ReportCalc.GetExpandedData() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting_Core_Lib\IRR_Reporting_Core_Lib\Calc.cs:line 302
      at IRR_Reporting.MainView.ExpandByParameter() in C:\CCViews\bfranklin_IRR_Redo_intg\VB_IRR\IRR_Reporting\IRR_Reporting\IRR_Reporting\MainView.cs:line 3042
    

    Which occurs at the following code:

     

    return Expression.Call(instance, (MethodInfo)method, args);
    

    Where instance is the UrlEncoded string, method is my static UrlDecode method, and args is System.Linq.Expressions.Expression[0]. I'm a litte lost on this but I'll keep digging - if you have any ideas please let me know - thank you!

    Brad

    Thursday, September 02, 2010 4:02 PM
  • Ok I figured it out - stop tried using UrlDecode as an extension method and just made a normal method call in the dynamic LINQ syntax. That worked! thanks!
    Thursday, September 02, 2010 8:02 PM
  • Glad to hear the problem is solved!  :-)   Thank you very much for sharing your solution here!

     

     

    Have a nice weekend!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, September 03, 2010 6:22 AM