Skip to content

"TargetException: Non-static method requires a target" when destructuring #1657

@vegardlarsen

Description

@vegardlarsen

Version used

Version 3.0.0-beta-2053.

Describe the bug

When destructuring a method out of an object provided from C# code, and then trying to invoke the method from Javascript, a TargetException is raised, stating Non-static method requires a target.

To Reproduce

void Main()
{
    var engine = new Engine();	
    engine.SetValue("test", new Test());
    engine.Execute("const { log } = test; log()");
}

class Test
{
    public void log() { Console.WriteLine("logging"); }
}

Expected behavior

I expect to be able to destructure an object from within Javascript and invoke its methods.

Additional context

  • If you mark the Test.log method as static, the problem disappears, but also the Test class won't have access to its instance fields/properties/methods, so it is not really a solution.
  • If you do not invoke the log method, there is no exception.
  • The problem with destructuring also occurs in other contexts, e.g. when using destructuring in a lambda: ({ log }) => log().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions