我试图使用https://github.com/MrRoundRobin/telegram.bot编写电报机器人, 它是Telegram Bots的C#api。
编译后的程序在Windows上运行没有任何问题,但是当尝试在Raspbian Linux(ARM处理器上的Debian)上使用Mono运行它时,它崩溃了
System.MissingMethodException: Method 'DateTimeOffset.FromUnixTimeSeconds' not found.
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable
加上整个堆栈跟踪的剩余部分。 telegram.bot方法使用Newtonsoft.Json显然序列化请求/反序列化响应。
Mono JIT compiler version 4.2.2 (Stable 4.2.2.30/996df3c Fri Jan 00:48:14 UTC 2016)
任何帮助都将不胜感激。
答案 0 :(得分:0)
它在旧的.Net版本中缺少DateTimeOffset.FromUnixTimeSeconds因为在Net 4.6中添加了这个扩展,我也会告诉MrRR修复后向兼容性,但是你的prj .Net版本可能是更低,也似乎你从方法中使用等待使用,所以它会抛出异常。
顺便说一下,你可以做些事情,
1:最常见的
try
{
// your code
var result = await bot.SendPhoto(id, file);
}
catch (Exception ex)
{
// handleing code
}
或更多,如您所知,更准确:
try
{
// your code
var result = await bot.SendPhoto(id, file);
}
//-- Because this exception is a kind of AggregateExceptions
catch (AggregateException ex)
// for C# 6.0 you can use when (somehow)
// catch (AggregateException ex) when (something to check Method not found)
{
// handleing code
}
2:你自己添加一个扩展程序(我还没有检查过)
尝试将具有精确“FromUnixTimeSeconds”的扩展添加到DateTimeOffset,并使用相同的返回值实现该方法。 要知道如何更好地实现它,例如.Net 4.6可以使用:https://msdn.microsoft.com/en-us/library/system.datetimeoffset.fromunixtimeseconds(v=vs.110).aspx
和ofc这是基本异常,某些人的完整堆栈跟踪可以帮助更多地了解这一点:
Method not found: 'System.DateTimeOffset System.DateTimeOffset.FromUnixTimeSeconds(Int64)'.
at Telegram.Bot.Helpers.UnixDateTimeConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, Encoding effectiveEncoding, IFormatterLogger formatterLogger)
at System.Net.Http.Formatting.JsonMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, Encoding effectiveEncoding, IFormatterLogger formatterLogger)
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.ReadFromStream(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Net.Http.HttpContentExtensions.<ReadAsAsyncCore>d__0`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Telegram.Bot.Api.<SendWebRequest>d__106`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at [Your Project and line code]
希望这些可以帮助你
如果您需要知道为什么会发生这种情况并且可以提供更多相关信息