# MethodError For Defined Function

**URL:** <https://discourse.julialang.org/t/methoderror-for-defined-function/130130>\
**Category:** General Usage\
**Tags:** question\
**Created:** [June 23, 2025, 12:27pm UTC](https://discourse.julialang.org/t/methoderror-for-defined-function/130130 "2025-06-23T12:27:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoh-meyers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoh-meyers/32/14700_2.png) [@yoh-meyers](https://discourse.julialang.org/u/yoh-meyers)\
**Post date:** [June 23, 2025, 12:27pm UTC](https://discourse.julialang.org/t/methoderror-for-defined-function/130130/1 "2025-06-23T12:27:32Z")

</div>

Hello,

I am back to using Julia, since more than 3 years break from the language.  
So I may not be most up-to-date with the latest changes.

That said, I am using my package [DanceJL](https://github.com/DanceJL/Dance.jl/tree/master) and am running into a MethodError, for something trivial that worked before.

To keep things simple, I have only added 1 endpoint and function:

```julia
using Dance.Router

function get_string()
    return "hello"
end

println(methods(get_string))
println(get_string())

route("/post_dict", get_string; method=GET, endpoint=EP_HTML)

```

Then I call this endpoint via Postman, to get a Method Error.

As you can see I have added print statements to debug.  
Output of above 2 is:

```julia
# 1 method for generic function "get_string" from Main.Backend:
 [1] get_string()
     @ ~Projects/Tracker/backend/routes.jl:3
hello

```

I have added another `println(methods(route.action))` to [where my package would be calling the newly defined function](https://github.com/DanceJL/Dance.jl/blob/fa4128d9b0c7fbb000619355d65d774819f8ffb2/src/engines/CoreEngine.jl#L119).  
And have removed the `headers` input, to keep things simple.

Output is:

```julia
# 1 method for generic function "get_string" from Main.Backend:
 [1] get_string()
     @ ~Projects/Tracker/backend/routes.jl:3

```

As we can see the endpoint function is recognised.

=\> Why do I still get a Method Error?

---

<div class="post-metadata">

**Author:** ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)\
**Post date:** [June 23, 2025, 12:34pm UTC](https://discourse.julialang.org/t/methoderror-for-defined-function/130130/2 "2025-06-23T12:34:04Z")

</div>

What’s the exact error message? What method is missing?

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [June 23, 2025, 12:35pm UTC](https://discourse.julialang.org/t/methoderror-for-defined-function/130130/3 "2025-06-23T12:35:20Z")

</div>

Yeah. Always include the full error message with the stack trace.

It would also be a good idea to ask a question that doesn’t depend on your package. That is, reduce your example to something that doesn’t depend on external packages.

---

<div class="post-metadata">

**Author:** ![yoh-meyers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoh-meyers/32/14700_2.png) [@yoh-meyers](https://discourse.julialang.org/u/yoh-meyers)\
**Post date:** [June 23, 2025, 1:18pm UTC](https://discourse.julialang.org/t/methoderror-for-defined-function/130130/4 "2025-06-23T13:18:28Z")

</div>

Exact error message I get is:

```julia
MethodError(Main.Backend.get_string, (), 0x0000000000006877)

```

As for stacktrace:

```julia
MethodError: no method matching get_string()
│ The function `get_string` exists, but no method is defined for this combination of argument types.
│ 
│ Closest candidates are:
│ get_string() (method too new to be called from this world context.)
│ @ Main.Backend ~Projects/Tracker/backend/routes.jl:3
│ 
│ 9-element Vector{Base.StackTraces.StackFrame}:
│ process_backend_function(; route::Dance.Router.Route, route_segments::Vector{String}, payload::String, headers::Dict{String, String}) at CoreEngine.jl:119
│ process_backend_function at CoreEngine.jl:78 [inlined]
│ render(; request_headers::Dict{String, String}, request_method::String, request_path::String, request_payload::String) at CoreEngine.jl:256
│ render at CoreEngine.jl:217 [inlined]
│ #2 at FlamencoEngine.jl:29 [inlined]
│ macro expansion at Server.jl:104 [inlined]
│ (::Flamenco.Server.var"#2#4"{Dance.CoreEngine.var"#2#3"})(x::Int64) at macros.jl:20
│ (::ThreadPools.var"#_fn#54"{Flamenco.Server.var"#2#4"{Dance.CoreEngine.var"#2#3"}, ThreadPools.var"#start#53"{ThreadPools.var"#finish#51"{ThreadPools.var"#len#50"{Int64, Int64, Int64}}, ThreadPools.var"#len#50"{Int64, Int64, Int64}}, ThreadPools.var"#finish#51"{ThreadPools.var"#len#50"{Int64, Int64, Int64}}, Vector{Nothing}, Vector{Int64}})(ind::Int64) at staticpool.jl:49
│ (::ThreadPools.var"#49#56"{ThreadPools.var"#_fn#54"{Flamenco.Server.var"#2#4"{Dance.CoreEngine.var"#2#3"}, ThreadPools.var"#start#53"{ThreadPools.var"#finish#51"{ThreadPools.var"#len#50"{Int64, Int64, Int64}}, ThreadPools.var"#len#50"{Int64, Int64, Int64}}, ThreadPools.var"#finish#51"{ThreadPools.var"#len#50"{Int64, Int64, Int64}}, Vector{Nothing}, Vector{Int64}}, Int64})() at macros.jl:261
└ @ Dance.CoreEngine ~/.julia/packages/Dance/eo9RS/src/engines/CoreEngine.jl:126

```

So I suppose key takeaway is `method too new to be called from this world context.`

Thank you

---

<div class="post-metadata">

**Author:** ![yoh-meyers](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yoh-meyers/32/14700_2.png) [@yoh-meyers](https://discourse.julialang.org/u/yoh-meyers)\
**Post date:** [June 23, 2025, 1:28pm UTC](https://discourse.julialang.org/t/methoderror-for-defined-function/130130/5 "2025-06-23T13:28:45Z")

</div>

Solved by adding `Base.invokelatest`
