尝试调用方法时,C# 执行停止且没有错误
首先我很困惑。我有一个 CMS 搜索模块,它在一个站点上运行良好,但在另一个站点上却无法正常运行。
我有这样的代码,我通过 Ajax 调用和加载搜索站点时调用:
private string GetSearchContent()
{
Query q = GetQuery();
//for each area, set it up, perform search and render result
IArea products = new ProductArea(GetEcomExcludedGroupIDs(), GetEcomLanguage()).Search(q);
IArea pages = new PageArea(GetAreaId())
.Search(q);
IArea news = new NewsArea(GetIncludedNewsCategoryIDs())
.Search(q);
....
}
这里重要的部分是搜索功能。这是在类中实现的,但由于某种原因代码不会被执行。
我尝试将代码分开,所以我确信这就是错误所在。奇怪的是,它不会抛出任何异常,但每当我尝试调用搜索函数时,它就会停止执行。它甚至没有进入该功能。
Search 函数如下所示:
public override IArea Search(Query q)
{
log.Debug("Product search");
....
}
它重写的函数只是声明该函数的接口上的抽象函数。
我尝试将函数复制到执行它的同一个类,但没有成功,并且我尝试访问类上的其他函数,效果很好。
那么我的问题是。什么可能导致这种行为?我尝试环顾四周,但找不到其他有同样问题的人。正如之前提到的,完全相同的代码在另一个站点上运行顺利。
我真的希望有人可以帮助我更接近解决问题,或者至少理解问题。
First of all I am stumped. I have a search-module for a CMS that runs fine on one site, but it won't run as it's supposed to on another site.
I have this code I call both with an Ajax call and simply when loading the search site:
private string GetSearchContent()
{
Query q = GetQuery();
//for each area, set it up, perform search and render result
IArea products = new ProductArea(GetEcomExcludedGroupIDs(), GetEcomLanguage()).Search(q);
IArea pages = new PageArea(GetAreaId())
.Search(q);
IArea news = new NewsArea(GetIncludedNewsCategoryIDs())
.Search(q);
....
}
The important part here is the Search function. This is implemented in the classes, but for some reason the code won't be executed.
I have tried splitting the code up so I am sure that is where the error lies. The freaky part is that it does not throw any exceptions, but it just stops executing whenever I try to call the Search function. It doesn't even enter the function.
The Search function looks like this:
public override IArea Search(Query q)
{
log.Debug("Product search");
....
}
The function it overrides is simply an abstract function on an interface that declares the function.
I have tried copying the function to the same class that are executing it with no luck, and I have tried accessing other functions on the classes, and that worked fine.
My question is then. What could cause this behavior? I have tried looking around but couldn't really find any others with the same problem. And as mentioned before, the exact same code is running smoothly on another site.
I really hope someone can help me get closer to a fix, or at least to understand the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题是无法回答的。您断言
Search
方法永远不会运行,并且错误的行是这一行:在
Search
方法之外可能存在一些不同的问题:GetIncludedNewsCategoryIDs
方法抛出异常你说“没有 try-catch”——更有理由不相信你的断言,即该方法只是停止而不抛出异常。出于诊断目的,请尝试以下操作:
如果您已运行此命令,并且仍然看到执行停止且没有记录任何异常,那么我们将考虑其他可能性。
The question is unanswerable as written. You assert that the
Search
method never runs, and that the faulty line is this one:There are a few different things that could be wrong outside of the
Search
method:NewsArea
constructor throws an exceptionGetIncludedNewsCategoryIDs
method throws an exceptionYou state that "there is no try-catch" -- all the more reason to disbelieve your assertion that the method just stops without throwing an exception. Try the following for diagnostic purposes:
If you've run this and still see that the execution stops without logging any exception, then we'll look at other possibilities.