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.

8
  • How are you getting line numbers from assemblies provided to a customer? Release assemblies don't generally have line number information in the PDBs... Commented Jul 18, 2012 at 20:32
  • The exception could be thrown inside the XyzConnection constructor? Commented Jul 18, 2012 at 20:33
  • 1
    You need the full stack trace. Commented Jul 18, 2012 at 20:34
  • 1
    Line numbers are unreliable. My advice: Rather than one long chain of operations, make it more granular: access the properties in turn into locals, with some exception handling/logging around each. Commented Jul 18, 2012 at 20:35
  • @PeterRitchie Its a debug build with pdb we have given to customer. Commented Jul 18, 2012 at 20:55

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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.)

3 Comments

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 approach in Java
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?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.