我有一个小问题,我想用DnSpy在一个应用程序中添加一个新的类C#。
我的班级是不和谐的Webhook.cs。
当我添加它并试图编译它时,它会显示一个错误:
“命名空间'System.Net‘中不存在类型或命名空间名称'Http’(是否缺少程序集引用?)”
我不知道如何使用DnSpy添加System.Net.Http,也没有添加它的源代码。
如果你想,我的课程是:
using System.IO;
using System.Net;
using System.Net.Http;
/*
* Created this for making it easier to use
*/
namespace Misaki
{
class Webhook
{
private HttpClient Client;
private string Url; //Url of the webhook
public string Name { get; set; }
public string ProfilePictureUrl { get; set; } //make sure that this is "" and not null if you don't wanna have it use a profile picture
public Webhook(string webhookUrl)
{
Client = new HttpClient();
Url = webhookUrl;
}
//method for sending the message (if file is null (which it is by default) no file will be included)
public bool SendMessage(string content, string file = null)
{
MultipartFormDataContent data = new MultipartFormDataContent();
data.Add(new StringContent(Name), "username");
data.Add(new StringContent(ProfilePictureUrl), "avatar_url");
data.Add(new StringContent(content), "content");
if (file != null)
{
//throws exception if file doesn't exist
if (!File.Exists(file))
throw new FileNotFoundException();
byte[] bytes = File.ReadAllBytes(file);
data.Add(new ByteArrayContent(bytes), "file", "file.txt");
}
var resp = Client.PostAsync(Url, data).Result;
return resp.StatusCode == HttpStatusCode.NoContent;
}
}
}谢谢你的帮助!
发布于 2019-12-11 08:19:46
右键单击VS项目中解决方案资源管理器中的References文件夹。如果您随后单击Add,您应该能够看到提示。查看System.Net或System.Net.Http是否在那里,以及它们是否已勾选。
https://stackoverflow.com/questions/59277000
复制相似问题