Developer forum

Forum » Development » System.MissingMethodException: Method '....' not found.

System.MissingMethodException: Method '....' not found.

Alexandru Aliu
Reply

Hey guys,

I have a schedule task that executes a method in a custom class. The process works fine in development and on staging server, but it doesn't work on the production server.  The error message is not too descriptive, it just says that Method '....' not found;  Is there any way I can figure out what is the problem ?

The namespace is wrong named , but I guess it should have anything to do with what's happening. This is the setup


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

I think "System.MissingMethodException" is very descriptive as it means that .NET tries to execute a method that doesn't exist in the DLL. So maybe prod has either an older version of the DLL or the set up isn't right? Maybe the namespace does have everything to do with it?

Imar

 
Alexandru Aliu
Reply

Well, as I said, the same namespace is used on the staging server and it works fine. Regarding the method, it's defenetly there since I am able to select it in "Method" dropdown 

During the development I encountered different errros, of course and I managed to fix them using the debug mode. In the interface, the error was always "Method not found" so it's not descriptive at all. Anyways, on the production I can't use debug mode to see what is the issue. I made a DB backup and I run it in my local instance and it works fine. 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

It's descriptive in the sense that it explains that it tries to execute something that doesn't exist. It could be a class name, namespace or method name that is different. But it could also be parameters. I think the add-in either expects a parameterless method or needs a match in parameters defined. Maybe yours has parameters that cannot be resolved at runtime? Or maybe the number of parameters you specified doesn't match with the number of parameters in your method?

 
Alexandru Aliu
Reply

This is the declaration

This is the setup:

 

This shouldnt have any issues. 

There something though, tat I don't have to much control though:

Could this crash the service somehow ? :-/ 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

>> Could this crash the service somehow ? :-/ 

I doubt it.

Does it say which method is missing?

 
Alexandru Aliu
Reply

This is the exact log 

2023-07-03 10:07:36.407: Method 'KBW.CustomModules.NotificationSubscribers.Payments.SubscriptionService.AutoCharge' not found.
System.MissingMethodException: Method 'KBW.CustomModules.NotificationSubscribers.Payments.SubscriptionService.AutoCharge' not found.
at Dynamicweb.Scheduling.MethodAddIn.MethodAddIn.Run()
at Dynamicweb.Scheduling.AddInJob.Execute()
2023-07-03 10:07:36.407: Request headers: [   "Cache-Control",   "Connection",   "Content-Length",   "Content-Type",   "Accept",   "Accept-Encoding",   "Accept-Language",   "Cookie",   "Host",   "Referer",   "User-Agent",   "sec-ch-ua",   "sec-ch-ua-mobile",   "sec-ch-ua-platform",   "upgrade-insecure-requests",   "origin",   "sec-fetch-site",   "sec-fetch-mode",   "sec-fetch-user",   "sec-fetch-dest" ]
2023-07-03 10:07:36.407: Request item keys: [   "ExecutionTableMapper",   "Dynamicweb.Environment.Web" ]
2023-07-03 10:07:36.407: Request form: [   "__EVENTTARGET",   "__EVENTARGUMENT",   "__VIEWSTATE",   "__VIEWSTATEGENERATOR",   "__EVENTVALIDATION",   "lstTasks:SortColumnIndex",   "lstTasks:SortDirection",   "lstTypes",   "dlgImpersonation$ImpersonationUsername",   "dlgImpersonation$ImpersonationPassword",   "dlgImpersonation$ImpersonationDomain",   "dlgImpersonation$DoImpersonation" ]
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

And can you show the full code for the class including the namespace? I would use a decompiler and look at the raw source for the DLL on the server.

Imar

 
Alexandru Aliu
Reply

There it is :-) 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Can you rename it to .txt  and try again? Also, is this the original source code or the decompiled code? I think the latter is important to ensure you are looking at what gets used.

 
Alexandru Aliu
Reply

It's the original code 

 
Alexandru Aliu
Reply

Oh, you want me to decompile the compiled version ? What's the point If I wrote it , compiled it and deployed it ? I can try to do that too ... 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

There is no point if they are indeed identical. However, since it doesn't work, something must be off. My guess is that the DLL on production doesn't contain what you think it does. 

I just set up the same concept on my end usign a method like this:

namespace KBW.CustomModules.NotificationSubscribers.Payments
{
  public class SubscriptionService
  {
    public void AutoCharge(string shopId, string paymentId, string stateId)
    {
    }
  }
}

 

and set up like this:

And it works as expected:

 
Alexandru Aliu
Reply

I've just come back from vacation while one of my colleagues found the issue. I will shortley explain here:

The error message thrown by DW is missleading. The DLL was ok, but one of the methods inside my service had an error. DW doesn't throw the BaseError Message, but instead throws  this "MissingMethodException: Method not found".

 

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

Hi Alexandru,

Dynamicweb does not throw the MissingMethodException. That one comes from .NET and is rethrown by DW. There is, however, an issue that might lead to this confusion.

The MethodAddin tries to run the method as specified, but if that fails (the case here), it will try to execute a static method with the same name. In other words, it tries to execute an instance method and if that fails, it assumes the method is static and tries again. If this also fails, the last exception is rethrown. This can lead to confusion as the MissingMethodException refers to the reflection invocation trying to find a static method with the given name but doesn't find it.

It is possible to see that this exception isn't the root cause of the issue, however, but it requires checking the logs in Dynamicweb. A log entry is made containing the message of the first exception as well as the last exception. Generally, it's a good idea to check the logs when something doesn't go as planned, as these messages might contain more information than an exception message does.

I'll make a task to get the logic around method invocation cleaned up, so the thrown exceptions are more indicative of the actual issue.

I hope that clears it up. otherwise let me know.

- Jeppe

Votes for this answer: 1
 
Alexandru Aliu
Reply

That makes sense, thank you :-) 

 

You must be logged in to post in the forum