当我调试我的应用程序时,我遇到了很多 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/