首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >InvalidOperationException和NullReferenceException

InvalidOperationException和NullReferenceException
EN

Stack Overflow用户
提问于 2011-11-24 03:03:35
回答 5查看 14.5K关注 0票数 2

当我调试我的应用程序时,我得到了很多这样的InvalidOperationException和NullReferenceException:

代码语言:javascript
复制
A first chance exception of type 'System.NullReferenceException' occurred in XGen.Framework.DLL
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
A first chance exception of type 'System.NullReferenceException' occurred in XGen.Framework.DLL
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
A first chance exception of type 'System.NullReferenceException' occurred in XGen.Framework.DLL
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
A first chance exception of type 'System.NullReferenceException' occurred in XGen.Framework.DLL
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
A first chance exception of type 'System.NullReferenceException' occurred in XGen.Framework.DLL
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
A first chance exception of type 'System.NullReferenceException' occurred in XGen.Framework.DLL
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll
A first chance exception of type 'System.NullReferenceException' occurred in XGen.Framework.DLL

它是如何使应用程序变慢的?

编辑:

找到发生InvalidOperationException的位置

代码语言:javascript
复制
public static Value.Locale Get(string value)
    {
        try
        { return _Items.First(itm => itm.ID.ToUpper() == value.ToUpper() || itm.Name.ToUpper() == value.ToUpper()); }
        catch (Exception)
        { return new XGen.Framework.Value.Locale(); }
    }

翻译的文本:序列不包含匹配的元素

我应该检查_Items.Count是否> 0吗?

EN

回答 5

Stack Overflow用户

回答已采纳

发布于 2011-11-24 03:46:18

如果他们没有让你的程序变慢,那他们应该是例外的。如果您知道您的_items可以为空,这不是异常,这是一个正常的流程,不应该用异常来处理它。您可以检查计数,或者只调用FirstOrDefault而不是First...

票数 2
EN

Stack Overflow用户

发布于 2011-11-24 03:09:56

它不可能让你的应用程序更快,所以,是的,它会让你的应用程序变慢,但“慢”当然是相对的。我更关心的是这些异常是由于应用程序中的逻辑错误造成的,而不是它的运行速度。

票数 3
EN

Stack Overflow用户

发布于 2011-11-24 03:16:59

你必须开始缩小范围,弄清楚到底发生了什么。我猜测的原因是这个XGen.Framework.DLL做了一些不好的事情(导致System.Core中的InvalidOperationException ),但却很好地为您处理它,这就是应用程序继续运行的原因。

您可以告诉调试器在第一次更改异常时停止,并检查堆栈跟踪。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8247693

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档