-1

I am working on an REST API which classes share most of their behaviour, like simple GET PUT POST DELETE.

There are A LOT of classes, for that reason i decided to create empty interfaces and generic methods with constraints to manage all its functionalities.

An example of how it looks:

Interface

public interface IGetByOwner
{
}  

Class

public class Customer : IGetByOwner
{
    public int OwnerID {get;set;}
}

Helper

public class LTHttpClient
{
    public static async Task<HttpResponseMessage> GetByOwner<T>(int ownerId)
        where T : IGetByOwner
    {
        var uri = $"{LTContext.apiRoot}/{typeof(T).Name}?ownerId={ownerId}";

        return await SendRequest(new HttpRequestMessage
        {
            Method = HttpMethod.Get,
            RequestUri = new System.Uri(uri)
        });
    }
}

Http GET

var response = await LTHttpClient.GetByOwner<Customer>(Owner.Id);

This works as expected. The problem are the other Http Methods.

Http POST

var response = await LTHttpClient.GetByOwner<Customer>(Owner.Id);

This throws an exception message:

System.MissingMethodException: 'Method not found: 
'System.Threading.Tasks.Task`1<System.Net.Http.HttpResponseMessage> 
LeafyTracker_PCL.LTHttpClient.Post(!!0)'.'

This code (All the transactions) runs on a PCL .NET Standard 2.0, and the methods are being called on a WinForm project meanwhile
What i am doing wrong?

UPDATE 01/06/2018

The issue seems to be an old reference of the library somewhere.
However, i already clean the solution, delete bin folder and rebuild all and the exception is still being throwed. Any advice?

  • Have you deliberately kept Http GET and Http POST exactly the same in the question? They're both "var response = await LTHttpClient.GetByOwner(Owner.Id);" – AD8 Jun 02 '18 at 07:56

2 Answers2

0

Did you check other posts, I found this answer by Polity on SO : https://stackoverflow.com/a/8059594/4794396 PS: couldn't leave a comment as I don't have 50 reputations yet, hence, an answer!

UPDATE: Including key points from the linked answer... It is likely that there are residual old versioned DLLs somewhere. Based on Ladenedge's comment on the above answer, it could be because of the GAC having older versions.

AD8
  • 2,168
  • 2
  • 16
  • 31
  • 1
    If you are going to link an answer, at least summarize the relevant bits of information in your own words – TheGeneral May 31 '18 at 03:21
  • @TheGeneral I understand the importance of summarizing the key points, hence, I have done so. That said, I would also prefer the questioner to look at the linked answer itself, as the answer and other answers / comments around the linked could help when the linked answer may not have helped. – AD8 May 31 '18 at 03:27
  • That did not work. I already clean my solution, also i added some other test methods on the library that do work. – Jose Belisario Jun 01 '18 at 14:18
  • You were right. The lastest dummy methods that i added also throw this error – Jose Belisario Jun 01 '18 at 14:46
  • Have you project grown with many classes and functions already? Or is it just the beginning and you’ve encountered this? If it is alright to share content, please have all relevant files shares somewhere and perhaps I’ll give it a try myself. Again, it is the nature of this issue, I wouldn’t have otherwise asked to share content. – AD8 Jun 01 '18 at 23:12
  • Also which version of VS are you using? – AD8 Jun 01 '18 at 23:14
0

I solved this by copying everything in the PCL which contains the interfaces into a new one, and changing all the references for the newest.