我不确定这是Edgejs的问题,我只是希望有人遇到同样的问题,并提出一些建议如何找出原因。无论如何,'进程因StackOverflowException而终止'应该是从.net运行时发生的,对吗?
图像
我的Nodejs代码是tcp服务器,每当收到数据时,它都会调用.net代码,.net代码只负责在sql server中存储数据。 Nodejs代码定义边缘函数如下:
module.exports.updateStation = edge.func({
assemblyFile: clrAssembly,
typeName: clrType,
methodName: 'UpdateStationAsync'
});
下面是updateStation功能的.net代码:
public async Task<object> UpdateStationAsync(dynamic station)
{
string projid = (string)station.projid;
string stid = (string)station.stid;
using (var context = new FlyDataContext(ConnectString))
{
var st = await context.Stations.FirstOrDefaultAsync(
s => s.ProjectID == projid && s.StationID == stid);
if (st != null)
{
st.IpAddress = (string)station.ip;
st.IpPort = (int)station.port;
st.ServerPort = (int)station.serverport;
st.LastCmd = (string)station.cmd;
st.LastUpdated = DateTime.Now;
}
else
{
st = new Station()
{
ProjectID = projid,
StationID = stid,
IpAddress = (string)station.ip,
IpPort = (int)station.port,
ServerPort = (int)station.serverport,
Interval = 10,
LastCmd = (string)station.cmd,
LastUpdated = DateTime.Now
};
context.Stations.Add(st);
}
return await context.SaveChangesAsync();
}
}
从Dll的配置文件中读取ConnectString,如下所示:
private static string _connString = null;
protected static string ConnectString
{
get
{
if (string.IsNullOrEmpty(_connString))
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
string configpath = Path.Combine(Path.GetDirectoryName(path), "Fly.Data.dll.config");
XDocument doc = XDocument.Load(configpath);
XElement root = doc.Root;
_connString = (from e in root.Element("connectionStrings").Elements("add")
where e.Attribute("name").Value == "FlyDataContext"
select e.Attribute("connectionString").Value).FirstOrDefault();
}
return _connString;
}
}
我只是使用Entity Framework来访问sql server,而不是更复杂的代码。我很困惑,我查看了我的代码,没有找到任何递归调用。
关键是StachOverflowException在程序运行一段时间后发生,并不总是发生在同一个地方或同一时间,对我来说很奇怪,看起来像是随机的,但异常总是发生一段时间后,它大概不会超过1分钟。