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?