当我调试我的应用程序时,我收到很多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吗?
最佳答案
好吧,如果它们不使您的程序变慢,那应该是例外。
如果您知道_items可以为空,这不是一个例外,那是正常流程,不应将其与例外一起处理。
您可以检查计数,或者直接调用FirstOrDefault
而不是First
...
关于c# - InvalidOperationException和NullReferenceException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8247693/