2

When I am debugging my Application, I got lots of InvalidOperationException and NullReferenceException Like this:

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

Does it makes application slower some how?

Edited:

Found where the InvalidOperationException is Happening

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(); }
    }

Translated text: The sequence contains no elements match

Should I check if _Items.Count > 0?

ShadowG
  • 683
  • 2
  • 10
  • 21

5 Answers5

3

It can't possibly make your application faster, so yes, it would make it slower, but of course "slower" is relative. I would be more concerned as to those exceptions being a result of a logical bug in your application than the speed at which it runs.

Daryl
  • 18,592
  • 9
  • 78
  • 145
  • since I'm having lots of this exceptions... I think it must be somewhere in the base class or base component class. by the way when I say lots, i mean really a lot – ShadowG Nov 23 '11 at 19:12
2

Well if they don't make your program slower, they should be exceptional. If you know that your _items can be empty that's not an exception, that's a normal flow, and it should not be handled with exceptions. You can check the count, or just call FirstOrDefault instead of First...

MBen
  • 3,956
  • 21
  • 25
  • I was about to answer my own question. The problem was in front of me and i didn't see. All I had to do was to use FirstOrDefault instead of First. – ShadowG Nov 23 '11 at 19:51
  • it happens, sometimes we need an external eye :) – MBen Nov 23 '11 at 20:06
1

You'll have to start narrowing those down, to figure out what's happening. My guess is the cause is this XGen.Framework.DLL doing something bad (causing an InvalidOperationException in System.Core), but handling it gracefully for you, which is why the application continues to function.

You can tell the debugger to stop on first change exceptions, and check the stack trace.

zmbq
  • 38,013
  • 14
  • 101
  • 171
1

See this answer from the Jon Skeet, he feels they do not slow down the application when used reasonably, however you situation doesn't seem normal:

If you ever get to the point where exceptions are significantly hurting your performance, you have problems in terms of your use of exceptions beyond just the performance.

How slow are .NET exceptions?

Community
  • 1
  • 1
rick schott
  • 21,012
  • 5
  • 52
  • 81
0

first chance exception means that somehwere in the code an exception was thrown but caught and handled. In your case you get a lot of NullReferenceException and InvalidOperationException which most of the times indicate a bug somewhere (property or field not initialized, calling an object in an invalid state). So I would not be worried so much about the speed but more about the correctness in your case.

ChrisWue
  • 18,612
  • 4
  • 58
  • 83