0

Lately, I encountered a slowdown in my website and already found the cause. The reason behind is because the methods in my DA layer has IEnumerable parameters instead of IQueryable. I already refactored the parameters in my DA and the solution was built successfully. However upon replacing the dll of DA in prod, the error method not found happened in the BL layer. The method it was looking for was the previous which has the IEnumerable parameter. Why am I encountering this when I built the code in my solution without fail?

NOTE: I did not replace any other dll except for the DA

Jan Lyndon Jasa
  • 162
  • 1
  • 10

1 Answers1

1

Why am I encountering this when I built the code in my solution without fail?

Because you're rebuilding your BL project as well, presumably. That's fine - the method still exists by name, and the new parameter type is presuambly compatible with the argument you're passing, so your source still compiles.

But when you try replacing just your DA assembly, when your BL assembly code executes, it's still looking for a method with the IEnumerable parameter, but that method doesn't exist any more, hence the exception.

Simply put, changing a method parameter type is not a backwardly-compatible change, in terms of binary compatibility.

Just rebuild the whole project, and replace everything that depends on your DA assembly, as well as the DA assembly itself. Ideally, replace absolutely everything you build - that way you know that you've got a consistent set of assemblies.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Ooh wow!! Maybe this explains why when I did the opposite (built my BL, reverted my DA), method still not found but now it looks for the IQueryable. Gotta check this out – Jan Lyndon Jasa Oct 20 '16 at 15:11
  • 1
    @JanLyndonJasa: Fundamentally, I would encourage you to redeploy *everything* you rebuild, rather than one assembly at a time. That way you know the set of assemblies is consistent. – Jon Skeet Oct 20 '16 at 15:12
  • Can't say much to a Jon Skeet answer, however, I'd like to add if you call a method. The runtime will find that method based on the SIGNATURE you called. Since parameters are part of the signature you'll not be able to call it if they change. – Noel Widmer Oct 20 '16 at 15:14
  • @NoëlWidmer: The runtime is also sensitive to the return type, which isn't part of the signature in C# terms. – Jon Skeet Oct 20 '16 at 15:29
  • @JonSkeet Wow, thanks for the lesson. Wasn't aware of that! :) – Noel Widmer Oct 20 '16 at 15:37
  • @NoëlWidmer: I had to check it myself before adding the comment :) – Jon Skeet Oct 20 '16 at 15:38