0

I have a customer report of an IndexOutOfRangeException but the line number at which it is reported has no array access! The line is of the form:

using (XyzConnection conn = new XyzConnection(anObject.aProperty.anotherProperty))

XyzConnection, anObject, etc are made up replaced names but the construct is essentially same.

Can the above itself throw IndexOutOfRangeException?

Is it possible that the array access (and exception) are in some code called from above line, i.e. the constructor or one of the property getters? How can I identify the correct location?

I should mention that the problem cannot be reproduced in development environment and I cannot install Visual Studio on the customer's machine.

Miserable Variable
  • 28,432
  • 15
  • 72
  • 133

2 Answers2

2

Can the above itself throw IndexOutOfRangeException?

That line can't in and of itself throw the exception.

Some code inside the XyzConnection constructor method could be doing it, Or, the property getter for anObject.aProperty could be throwing it, or the property getter for aProperty.anotherProperty could also be throwing. My bet would be that it is one of the property getters.

They could be being inlined by the JIT compiler, and hence you wouldn't see them in the stack trace, no matter what PDB's you had. This is actually quite common, as propert getters are usually small and simple, which makes them ideal candidates for inlining.

I'd recommend a solid code review of those 2 property getters, followed by the XyzConnection constructor

Orion Edwards
  • 121,657
  • 64
  • 239
  • 328
  • The property getters are trivial but the constructor is not so I doubt it would be inlined. Is there any other reason the stack trace will give incorrect method/line number? I will follow your advice of code review. – Miserable Variable Jul 19 '12 at 00:36
0

The first thing that comes to mind is that the PDB doesn't match the DLL version being used. Nothing about the line of code hints at an Index Out of Range exception. Without seeing the code surrounding that call, and the constructor declaration itself, I doubt there's much help people can give.

One other thing to check in terms of misleading line numbers, if the code is using try/catch blocks, ensure that catch blocks that are re-raising exceptions are using "throw;" not "throw ex;" (where ex is the caught exception.) This causes the exception trace stack to be re-generated. (both time consuming, and overwrites potentially useful info.)

Steve Py
  • 26,149
  • 3
  • 25
  • 43
  • I did not know about `throw` v/s `throw ex`. It could well cause some other issues we are facing. I am pretty sure they are using the correct DLL but it there a way for me to know for sure which dll is getting loaded? I am thinking of something like [this](http://stackoverflow.com/a/4546650/18573) approach in Java – Miserable Variable Jul 18 '12 at 22:47
  • Yes, you can get the assembly details via reflection, but that means distributing new assemblies to the client. It raises a few questions such as whether the assembly is loaded from GAC, or expected to be loaded from the running directory. Is it part of an application, Windows Service, or web application? – Steve Py Jul 19 '12 at 00:48
  • It is an application. The problem reproduces on client's machine and I can provide them with new assemblies. I cannot install visual studio on that machine so short of that any other mechanism is fine. this is not the best code you see out there so if I have an alternative to code review I would be really happy. – Miserable Variable Jul 19 '12 at 01:00