Mono fix compiled issue "Are you missing `System.Net.Http' assembly reference?"
阿新 • • 發佈:2019-02-16
寫了個例子程式
using System; using System.Net.Http; using System.Threading.Tasks; namespace Chapter1.Threads { public static class Program { public static void Main() { string result = DownloadContent().Result; Console.WriteLine(result); } public static async Task<string> DownloadContent() { using(HttpClient client = new HttpClient()) { string result = await client.GetStringAsync("http://www.microsoft.com"); return result; } } } }
但是用mcs 編譯時,報錯
async1.cs(2,18): error CS0234: The type or namespace name `Http' does not exist in the namespace `System.Net'. Are you missing `System.Net.Http' assembly reference?
解決方法:用/reference 加上依賴的DLL
mcs /reference:System.Net.Http async1.cs