MissingMethodException C# NET 标准
MissingMethodException C# NET Standard
我正在研究 REST API,它 类 共享他们的大部分行为,例如简单的 GET PUT POST DELETE。
有很多 类,因此我决定创建带有约束的空接口和通用方法来管理其所有功能。
外观示例:
界面
public interface IGetByOwner
{
}
Class
public class Customer : IGetByOwner
{
public int OwnerID {get;set;}
}
帮手
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 获取
var response = await LTHttpClient.GetByOwner<Customer>(Owner.Id);
这按预期工作。问题出在其他 Http 方法上。
httpPOST
var response = await LTHttpClient.GetByOwner<Customer>(Owner.Id);
这将引发异常消息:
System.MissingMethodException: 'Method not found:
'System.Threading.Tasks.Task`1<System.Net.Http.HttpResponseMessage>
LeafyTracker_PCL.LTHttpClient.Post(!!0)'.'
此代码(所有事务)在 PCL .NET Standard 2.0 上运行,同时在 WinForm 项目上调用方法
我做错了什么?
更新 01/06/2018
这个问题似乎是某处图书馆的旧引用。
但是,我已经清理了解决方案,删除了 bin 文件夹并重建了所有内容,但仍然抛出异常。有什么建议吗?
你查看其他帖子了吗,我在 Polity 上找到了这个答案:
PS:无法发表评论,因为我还没有 50 个声誉,因此,一个答案!
更新:包括链接答案中的要点...
某处可能存在残留的旧版本 DLL。根据 Ladenedge 对上述答案的评论,可能是因为 GAC 的版本较旧。
我通过将包含接口的 PCL 中的所有内容复制到一个新的接口,并将所有引用更改为最新的引用来解决这个问题。
我正在研究 REST API,它 类 共享他们的大部分行为,例如简单的 GET PUT POST DELETE。
有很多 类,因此我决定创建带有约束的空接口和通用方法来管理其所有功能。
外观示例:
界面
public interface IGetByOwner
{
}
Class
public class Customer : IGetByOwner
{
public int OwnerID {get;set;}
}
帮手
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 获取
var response = await LTHttpClient.GetByOwner<Customer>(Owner.Id);
这按预期工作。问题出在其他 Http 方法上。
httpPOST
var response = await LTHttpClient.GetByOwner<Customer>(Owner.Id);
这将引发异常消息:
System.MissingMethodException: 'Method not found:
'System.Threading.Tasks.Task`1<System.Net.Http.HttpResponseMessage>
LeafyTracker_PCL.LTHttpClient.Post(!!0)'.'
此代码(所有事务)在 PCL .NET Standard 2.0 上运行,同时在 WinForm 项目上调用方法
我做错了什么?
更新 01/06/2018
这个问题似乎是某处图书馆的旧引用。
但是,我已经清理了解决方案,删除了 bin 文件夹并重建了所有内容,但仍然抛出异常。有什么建议吗?
你查看其他帖子了吗,我在 Polity 上找到了这个答案: PS:无法发表评论,因为我还没有 50 个声誉,因此,一个答案!
更新:包括链接答案中的要点... 某处可能存在残留的旧版本 DLL。根据 Ladenedge 对上述答案的评论,可能是因为 GAC 的版本较旧。
我通过将包含接口的 PCL 中的所有内容复制到一个新的接口,并将所有引用更改为最新的引用来解决这个问题。