c# - C# 代码适用于本地构建,但不适用于实时生产构建
问题描述
我一直在努力扩展我网站的搜索栏功能,以允许更多动态的搜索结果。当我在本地机器上使用调试器进行测试时,使用测试标签和搜索,它运行良好。但是,当我尝试构建它并将其发布到生产环境时,它不起作用。我已经逐行查看,我似乎无法找到代码中的问题所在。
它的工作方式是,对于我服务器上的文件,它会查看“类别”和“标签”值并将它们附加到列表中。例如,我有一个名为“Annual Results”的文件。“Annual Results”文件有一个“Financials”类别,并有标签“Results;Money;”。我还有一个名为“SynonymsDictionary”的文件,是的,它只是一个词库,位于 path TagSynonynmsPath
。在该文件中,它包含如下列表:
Results: Result;End;Close;
Financials: Finance;Financial;
Money: Moolah;Cash;Dollars;
...
Dictionary<string, string> synonymsDictionary = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(File.ReadAllText(Server.MapPath(".") + urlInfo.TagSynonymsPath));
/* Declare the tagList list that will store all of our populated tags */
List<string> tagList = new List<string>();
/* Add file categories to tagList */
foreach(string catTag in file.Value["Categories"].Split(';'))
{
tagList.Add(catTag.ToLower().Trim());
}
/* Add file tags to tagList */
foreach(string fileTag in file.Value["Tags"].Split(';'))
{
tagList.Add(fileTag.ToLower().Trim());
}
/* Loop through the newly populated category and tag objects to see if there are synonyms */
for (int i = tagList.Count - 1; i >= 0; i--)
{
/* Declare & initialize a new string where we can store our synonyms */
string synTags = string.Empty;
if (synonymsDictionary.TryGetValue(tagList[i], out synTags))
{
/* If a string of synonyms is found, split the string up into individual objects and add to tagList */
foreach(string cleanedTag in synTags.Split(','))
{
tagList.Add(cleanedTag.ToLower().Trim());
}
} else {
/* If there are no synonyms, test the next object in the list */
continue;
}
}
/* Convert our list into a string of tags, delimited with a ", " */
file.Value["Tags"] = String.Join(", ", tagList.ToArray());
代码应该首先存储我们的类别和标签,tagList
以便列表应该包含Financials,Results,Money
. 然后它查看 SynonymsDictionary 文件中的 KeyValuePairs 并看到每个标签都有一个同义词,所以它应该导致:
Financials,Results,Money,Finance,Financial,Result,End,Close,Moolah,Cash,Dollars
。这与我在本地测试时的结果完全一样,但是当我在我的实际站点上构建和发布解决方案时,它会中断。当我在本地测试它时,同义词比在现场要少得多。任何想法为什么这段代码没有实时运行?
解决方案
在本地针对小型数据集进行测试,然后针对大型数据集在生产环境中运行,总是容易让您陷入内存不足错误和超时等问题。如果没有捕获到实际错误,我们无法告诉您问题出在哪里,但是您可以通过在本地运行以下命令来攻击它:
- 生产数据的忠实副本
- 即使在应用程序池崩溃时,您也可以在这部分代码周围进行足够的日志记录,以便您获得有用的线索。
推荐阅读
- python - Jupyter Notebook 无法在命令行中运行代码
- python - 在开发过程中如何使用 Keras 获得可重现的结果?
- android - java.lang.NoClassDefFoundError 与 Kotlin 数据类
- vb.net - 显示新表单时的视觉基本问题
- azure - 如何通过terraform将本地文件复制到azure vm?
- c++ - 3d 三角形卡住了 c++ opengl glfw
- flutter - 如何为给定类型的 Flutter 小部件强制执行某些参数值?
- javascript - 如何将参数注入 TestCafé 测试?
- authorization - 微服务中的授权 - 用户可以访问的行列表
- sql - SQL Server:为临时表创建聚集索引