繁体   English   中英

C#代码适用于本地构建,但不适用于实时生产构建

[英]C# code works on local build, but not on live production build

我一直在努力扩展我的网站的搜索栏功能,以允许更动态的搜索结果。 当我在本地计算机上使用调试器进行测试时,使用测试标签和搜索,它完美地运行。 但是,当我尝试构建它并将其发布到生产时,它不起作用。 我已经逐行查看了,我似乎无法找到代码中的问题。

它的工作方式是,对于我服务器上的文件,它会查看“类别”和“标签”值,并将它们附加到列表中。 例如,我有一个名为“Annual Results”的文件。 “年度结果”文件具有“财务”类别,并具有“结果;货币;”标签。 我还有一个名为“SynonymsDictionary”的文件,是的,它只是一个同义词库,位于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 这个结果与我在本地测试时的结果完全相同,但是当我在实际站点上构建和发布解决方案时,它会中断。 当我在本地测试它时,同义词比在现场网站上少得多。 有什么想法为什么这段代码没有直播?

在本地针对小型数据集进行测试,然后针对大型数据集进行生产运行总是会导致内存错误和超时等问题。 如果没有捕获到实际错误,我们无法告诉您问题是什么,但您可以通过以下方式在本地运行来攻击它:

  • 忠实的生产数据副本
  • 足够记录这部分代码,即使应用程序池崩溃,您也可以获得有用的线索。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM