【发布时间】:2020-02-12 10:35:30
【问题描述】:
我在 .NET Core 中为 linux 编写了一个控制台应用程序。当我尝试在我的 linux vps 上运行它时,它会抛出该错误:
Could not resolve type with token 01000010
at Lumo.Program.Main (System.String[] args) [0x00039] in <dff92c70c42444648f6bf1be28aa709c>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeLoadException: Could not resolve type with token 01000010
at Lumo.Program.Main (System.String[] args) [0x00039] in <dff92c70c42444648f6bf1be28aa709c>:0
这是我的主要 C# 代码:
string city;
Console.WriteLine("lolyweather");
Thread.Sleep(1000);
Console.Write("Enter your city: ");
city = Console.ReadLine();
string link = "https://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=" + API_KEY + "&units=metric&cnt=6";
GetWeather(link, city);
这里是 GetWeather 函数:
public static void GetWeather(string url, string city)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Method = "GET";
try
{
using (WebResponse response = httpWebRequest.GetResponse())
{
HttpWebResponse httpResponse = response as HttpWebResponse;
using (StreamReader reader = new StreamReader(httpResponse.GetResponseStream()))
{
var json = reader.ReadToEnd();
var obj = JsonConvert.DeserializeObject<WD.RootObject>(json);
WD.RootObject weather = obj;
Console.WriteLine("There are " + weather.weather[0].main.ToString() + " in {0}", city);
Console.WriteLine("There are {0} \u00B0C.", Math.Round(weather.main.temp));
Console.WriteLine("Max temperature: {0}, Minimum temperature: {1}", Math.Round(weather.main.temp_max), Math.Round(weather.main.temp_min));
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Program crashed: {ex.Message} (Check if you wrote your city's name correctly!)");
Thread.Sleep(1_000);
}
}
有人知道怎么回事吗?
【问题讨论】:
-
删除您的
bin和obj文件夹,重建。这行得通吗? -
我刚试过。可惜没有
-
csproj 文件中的
是什么? -
@James
<TargetFramework>netcoreapp2.2</TargetFramework>就是这个 -
什么样的Linux VPS?请更具体。还有你用来运行应用程序的命令是什么。
标签: c# .net linux windows .net-core