当我调试我的应用程序时,我得到了很多这样的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吗?
发布于 2011-11-24 03:46:18
如果他们没有让你的程序变慢,那他们应该是例外的。如果您知道您的_items可以为空,这不是异常,这是一个正常的流程,不应该用异常来处理它。您可以检查计数,或者只调用FirstOrDefault而不是First...
发布于 2011-11-24 03:09:56
它不可能让你的应用程序更快,所以,是的,它会让你的应用程序变慢,但“慢”当然是相对的。我更关心的是这些异常是由于应用程序中的逻辑错误造成的,而不是它的运行速度。
发布于 2011-11-24 03:16:59
你必须开始缩小范围,弄清楚到底发生了什么。我猜测的原因是这个XGen.Framework.DLL做了一些不好的事情(导致System.Core中的InvalidOperationException ),但却很好地为您处理它,这就是应用程序继续运行的原因。
您可以告诉调试器在第一次更改异常时停止,并检查堆栈跟踪。
https://stackoverflow.com/questions/8247693
复制相似问题