c# - InvalidOperationException 和 NullReferenceException

标签 c# asp.net .net

当我调试我的应用程序时,我遇到了很多 InvalidOperationException 和 NullReferenceException,如下所示:

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 的地方

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 吗?

最佳答案

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

关于c# - InvalidOperationException 和 NullReferenceException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8247693/

相关文章:

c# - 如何在静态类中使用多态或继承?

C# 重新抛出异常

c# - 如何从 asp.net 处理程序返回 404 错误?

.net - POCO 是什么意思?

c# - "Throttle"一个函数

c# - 检查字符串是否仅包含有效的 ISO 8859-1 字符

C# yield 返回性能

asp.net - 检索 HttpWebResponse 并将其放入 XDocument 的有效方法

c# - EF - 调用 SaveChanges() 的类

C# 泛型 : Constraining T where T : Object doesn't compile; Error: Constraint cannot be special class 'object'