Telegram.Bot SendLocationAsync 仅在作为服务运行时返回"Input string was not in a correct format"



我正在运行一个C#.Net Core控制台应用程序作为服务(使用Topshelf(,除了Telegram.Bot SendLocationAsync返回错误:"输入字符串格式不正确"之外,一切都很好

在调试模式下,它与发布控制台应用程序一样工作良好。其他Telegram消息100%有效。这肯定是只有当我运行应用程序作为服务。

欢迎有什么想法吗?

使用的一些示例代码:

string locString = "-25.2567752,28.7920051";
try
{
string[] cam_loc = locString.Split(",");
double Lat = Convert.ToDouble(cam_loc[0]);
double Long = Convert.ToDouble(cam_loc[1]);
var Result1 = await Bot.SendLocationAsync(chatId: -625759052, latitude: (float)Lat, longitude: (float)Long);
}
catch (Exception ex)
{
Log.Error("Error Location Send: " + ex.Message);
}

发现的问题是区域性信息没有正确解析

以下修复了问题:

double.TryParse(cam_loc[0],NumberStyles.Number,CultureInfo.InvariantCulture,outLat_(

if (double.TryParse(cam_loc[0], NumberStyles.Number, CultureInfo.InvariantCulture, out 
Lat_) && double.TryParse(cam_loc[1], NumberStyles.Number, 
CultureInfo.InvariantCulture, out Long_))
{
Log.Debug("Lat/Long values: " + Lat_.ToString() + " / " + Long_.ToString());
try
{
var Result1 = await Bot.SendLocationAsync(chatId: vp.cliGroup, latitude: 
(float)Lat_, longitude: (float)Long_);
}
catch (Exception ex)
{
Log.Error("Error Location Send: " + ex.Message);
}
}
else
Log.Debug("Lat/Long (err) values: " + Lat_.ToString() + " / " + Long_.ToString());

相关内容

最新更新