0

I ran into one very simple issue but not able to understand its cause. Here is the brief of issue.

I am referencing dll of one project say B into project A. referenced dll has 3 classes in all and I am able use methods in all classes into project A except methods in one class. When I try to use methods of that one particular class it gives run-time exception as "Method not found".

I tried all various common ways like using latest version of dll, rebuilding, cleaning solutions. Does anyone has any idea related to such issue?

Structure of that class

public static class Sample
    {

    public static bool Method1(string parameter1)
        {
        //Method's logic

        return true;
        }
}

Strange thing is that if I refer that dll in some other project of other solution it works good. I doubt if my solution has some issues.

Ajinkya Wani
  • 39
  • 1
  • 10
  • 6
    Can you provide relevant code? – Krzysztof Bracha Jun 13 '17 at 12:14
  • 1
    Is it possible that the class in mention is an inner class or is marked private? – josephmbustamante Jun 13 '17 at 12:15
  • @josephmbustamante It is possible, but hardly relevant I think. – Patrick Hofman Jun 13 '17 at 12:16
  • post code for that class – Rahul Jun 13 '17 at 12:16
  • 2
    Thanks @josephmbustamante but class is public static class and I can see that class and all its methods in object browser. If it was a private or inner class it would not visible in object browser. – Ajinkya Wani Jun 13 '17 at 12:18
  • This is always a dll reference issue; the versions you are shipping are either not the versions you are referencing, or the versions you are referencing are not compatible with each-other (meaning B wants version X of lib C, A wants version Y of lib C, it is Y that is in your executable folder, so A is happy but B is sad) – Marc Gravell Jun 13 '17 at 12:21
  • @Rahul Posted code structure of that class – Ajinkya Wani Jun 13 '17 at 12:23
  • So the `Method1` is defined to accept only a string parameter, and you are trying to pass two more parameters to the same. then how it works? What you are expected the compiler to do in this case? also, consider that some how you managed with overloading or modifying the signature then when will it stop? – sujith karivelil Jun 13 '17 at 12:26
  • @un-lucky Those are overloaded methods. No any compiler errors for that. – Ajinkya Wani Jun 13 '17 at 12:28
  • @AjinkyaWani: Fine then when will you post the relevant codes? and how you are trying to call the `Method1`, have you tried `Sample.Method1("myParam");` – sujith karivelil Jun 13 '17 at 12:29
  • Have you checked any of these : https://stackoverflow.com/questions/3833674/c-sharp-method-not-found-exception-on-runtime-without-usage-of-reflection OR https://stackoverflow.com/questions/7578583/method-not-found-on-runtime OR https://stackoverflow.com/questions/8058832/system-missingmethodexception-method-not-found. – PaulF Jun 13 '17 at 12:31
  • @un-lucky Code structure I posted is exactly same as I am using. I can't post original code since its too large. And yes I am calling method same as you mentioned above – Ajinkya Wani Jun 13 '17 at 12:48

1 Answers1

1

I got this error a few times when I reference a shared project from multiple other projects, but in different versions. For example, B references A v1.0.0 but another project C references A v1.0.1. Under these circumstances, the compiler is just fine because all projects build against their dependencies. However, at runtime, the thing crashes because only v1.0.1 of A is loaded that does not contain the method that suddenly went away in v1.0.1.

Georg
  • 5,626
  • 1
  • 23
  • 44
  • Hi, This sounds relevant but how can it be related in my case since I have only 2 projects A and B and I am referencing latest version of B into A. – Ajinkya Wani Jun 13 '17 at 12:34
  • If you have added Project B into the solution of Project A then you need to ensure that when you compile the solution Project B's DLL is either created or copied to the solution folder for Project A. At compile time the method will be found in Project B, but if the correct version of the DLL is not in the correct folder at runtime - then you will get the Method Not Found exception. – PaulF Jun 13 '17 at 12:42