Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error No public methods with the specified arguments were found #1637

Closed
hyzx86 opened this issue Sep 19, 2023 · 9 comments · Fixed by #1638
Closed

error No public methods with the specified arguments were found #1637

hyzx86 opened this issue Sep 19, 2023 · 9 comments · Fixed by #1638

Comments

@hyzx86
Copy link
Contributor

hyzx86 commented Sep 19, 2023

Version used
3.0.0-beta-2052
Describe the bug

Hi ,

I used Jint and FreeSql to encapsulate the changes of different databases and operate on the data. Recently, I encountered a problem.
Update from beta-2049 to beta-2052
An exception is thrown. No public methods with the specified arguments were found.

See the last line for an example

  var db = await new FreeSqlMethodsProvider().UseDbAsync(scope.ServiceProvider);
  var total = db.SelectTypedQuery("UserProfile").Where("1=1").Any();

  engine.SetValue("objSelect", objSelect);
  var result1 = engine.Evaluate("objSelect.where('1=1')");//pass
  engine.SetValue("result1", result1);
  var result2 = engine.Evaluate("result1.any()");//error No public methods with the specified arguments were found

ISelect SelectTypedQuery(string)

Where Method:

        /// <summary>
        /// 原生sql语法条件,Where("id = @id", new { id = 1 })<para></para>
        /// 提示:parms 参数还可以传 Dictionary&lt;string, object&gt;
        /// </summary>
        /// <param name="sql">sql语法条件</param>
        /// <param name="parms">参数</param>
        /// <returns></returns>
        TSelect Where(string sql, object parms = null);

https://github.com/dotnetcore/FreeSql/blob/be6f2fa9c2cc04ce5bf01fc38d2b01a493021088/FreeSql/Interface/Curd/ISelect/ISelect0.cs#L291-L298

Any Method:

        /// <summary>
        /// 执行SQL查询,是否有记录
        /// </summary>
        /// <returns></returns>
        bool Any();

https://github.com/dotnetcore/FreeSql/blob/be6f2fa9c2cc04ce5bf01fc38d2b01a493021088/FreeSql/Interface/Curd/ISelect/ISelect0.cs#L195-L200

When I debug in jint, I find that I want to call bool Any();

But always call to bool Any(Expression<Func<T1, bool>> exp);
And it's the only one of the methods

/// <summary>
        /// 执行SQL查询,是否有记录
        /// </summary>
        /// <param name="exp">lambda表达式</param>
        /// <returns></returns>
        bool Any(Expression<Func<T1, bool>> exp);

https://github.com/dotnetcore/FreeSql/blob/be6f2fa9c2cc04ce5bf01fc38d2b01a493021088/FreeSql/Interface/Curd/ISelect/ISelect1.cs#L36C1-L41C50

@viruscamp
Copy link
Contributor

    public interface I0
    {
        string NameI0 { get => "I0.Name"; }
        string OverloadSuperMethod() => "I0.OverloadSuperMethod()";
        string SubPropertySuperMethod() => "I0.SubPropertySuperMethod()";
    }

    public interface I1 : I0
    {
        string Name { get; }
        string OverloadSuperMethod(int x) => $"I1.OverloadSuperMethod(int {x})";
        new string SubPropertySuperMethod => "I1.SubPropertySuperMethod";
    }

    [Fact]
    public void CallSuperPropertyFromInterface()
    {
        Assert.Equal(holder.I1.NameI0, _engine.Evaluate("holder.I1.NameI0"));
    }

    [Fact]
    public void CallOverloadSuperMethod()
    {
        Assert.Equal(holder.I1.OverloadSuperMethod(1), _engine.Evaluate("holder.I1.OverloadSuperMethod(1)"));
        Assert.Equal(holder.I1.OverloadSuperMethod(), _engine.Evaluate("holder.I1.OverloadSuperMethod()"));
    }

    [Fact]
    public void CallSubPropertySuperMethod()
    {
        Assert.Equal(holder.I1.SubPropertySuperMethod, _engine.Evaluate("holder.I1.SubPropertySuperMethod"));
        // Property and method cannot coexist
        Assert.Throws<Exception>(() => _engine.Evaluate("holder.I1.SubPropertySuperMethod()"));
    }

You PR pass CallOverloadSuperMethod but break CallSubPropertySuperMethod.

IMO, we'd better refactor TypeResolver , take care of the search order.
And fill property cache when loaded, remove property lazyload.

@hyzx86
Copy link
Contributor Author

hyzx86 commented Sep 21, 2023

You PR pass CallOverloadSuperMethod but break CallSubPropertySuperMethod.

How is the holder instantiated in your code?

IMO, we'd better refactor TypeResolver , take care of the search order. And fill property cache when loaded, remove property lazyload.

Yes I agree, suggest refactoring TryFindMemberAccessor into replaceable logic ,Just like the MemberNameCreator and the MemberNameComparer 😁

@Genteure
Copy link
Contributor

I searched around in https://github.com/dotnetcore/FreeSql on GitHub (so not in an IDE) and I can't seem to find an implementation of ISelect0. Can you tell me what's the concrete type of objSelect in your initial example code please?

@hyzx86
Copy link
Contributor Author

hyzx86 commented Sep 21, 2023

@Genteure Here is a unit test in FreeSql

SqliteSelectTest

In my project ,my method will retrun a type of ISelect<object>
like this:

        public ISelect<object> SelectTypedQuery(string typeName = default)
        {
            if (string.IsNullOrEmpty(typeName))
            {
                return FreeSql.Select<object>().AsType(typeof(ContentItemIndex));
            }

            var indexService = _serviceProvider.GetRequiredService<IDynamicIndexAppService>();
            var type = indexService.GetDynamicIndexType(typeName);
            if (type != null)
            {
                return FreeSql.Select<object>().AsType(type);
            }
            else
            {
                throw new Exception($"Type not found. : {typeName} ");
            }
        }

@Genteure
Copy link
Contributor

@hyzx86 我是想问它的实际运行时的类型是什么,方便我确认一下现在的 unit test 是否能代表实际你遇到的问题。我对那个项目不熟悉,项目里面的抽象层又太多,我在 GitHub 上搜索代码找不到一个实现了 ISelect0, ISelect1 的 concrete type。

objSelect.GetType().FullName

@hyzx86
Copy link
Contributor Author

hyzx86 commented Sep 21, 2023

@Genteure
With the help of @viruscamp , I have reproduced this problem using the code he provided.

image

@hyzx86
Copy link
Contributor Author

hyzx86 commented Sep 21, 2023

@hyzx86 我是想问它的实际运行时的类型是什么,方便我确认一下现在的 unit test 是否能代表实际你遇到的问题。我对那个项目不熟悉,项目里面的抽象层又太多,我在 GitHub 上搜索代码找不到一个实现了 ISelect0, ISelect1 的 concrete type。

objSelect.GetType().FullName

FreeSql.Sqlite.Curd.SqliteSelect`1[[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]

@hyzx86
Copy link
Contributor Author

hyzx86 commented Sep 21, 2023

@Genteure 回复完 我愣了一下。。。我以为浏览器开了翻译。。原来你发的就是中文🤣

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants