尝试调用方法时,C# 执行停止且没有错误

发布于 2024-11-19 05:27:17 字数 1030 浏览 1 评论 0原文

首先我很困惑。我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

回眸一笑 2024-11-26 05:27:17

这个问题是无法回答的。您断言 Search 方法永远不会运行,并且错误的行是这一行:

IArea news = new NewsArea(GetIncludedNewsCategoryIDs()).Search(q);

Search 方法之外可能存在一些不同的问题:

  • < code>NewsArea 构造函数抛出异常
  • GetIncludedNewsCategoryIDs 方法抛出异常
  • 上述任一方法都可以调用非托管代码并生成本机 Win32 异常,在某些情况下,这将简单地导致进程终止而不是返回到托管代码。

你说“没有 try-catch”——更有理由不相信你的断言,即该方法只是停止而不抛出异常。出于诊断目的,请尝试以下操作:

try
{
    IArea news = new NewsArea(GetIncludedNewsCategoryIDs()).Search(q);
}
catch (Exception e)
{
    Logger.Log("Caught in the act: " + e.ToString());
    throw;
}

如果您已运行此命令,并且仍然看到执行停止且没有记录任何异常,那么我们将考虑其他可能性。

The question is unanswerable as written. You assert that the Search method never runs, and that the faulty line is this one:

IArea news = new NewsArea(GetIncludedNewsCategoryIDs()).Search(q);

There are a few different things that could be wrong outside of the Search method:

  • The NewsArea constructor throws an exception
  • The GetIncludedNewsCategoryIDs method throws an exception
  • Either of the above could call into unmanaged code and generate a native Win32 exception, which under some circumstances will simple cause the process to terminate rather than ever returning to managed code.

You 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:

try
{
    IArea news = new NewsArea(GetIncludedNewsCategoryIDs()).Search(q);
}
catch (Exception e)
{
    Logger.Log("Caught in the act: " + e.ToString());
    throw;
}

If you've run this and still see that the execution stops without logging any exception, then we'll look at other possibilities.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文