Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Understanding errors in late-bound functions

In an asp.net app I'm developing, I encoutered this error:


Exception Details: System.InvalidCastException: Cast from type 'DBNull' to type 'String' is not valid.

Source Error:
[[ aspx source file snippet removed ]]


Source File: [[filename removed]]  Line: 55

Stack Trace:

[InvalidCastException: Cast from type 'DBNull' to type 'String' is not valid.]
  Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn) +792
Microsoft.VisualBasic.CompilerServices.LateBinding.LateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack) +23
[[ rest of stack trace removed ]]

As far as I can figure out, this is what happened: one of my functions (that's the part of the stack trace that I removed) called a function which is apparently late-bound. The VB.net compiler did whatever it does and called the function, which threw an exception. The VB.net compiler (Microsoft.VisualBasic.CompilerServices.LateBinding.LateCall to be precise) caught the exception and re-threw it, thus losing the crucial stack trace information which would have told me where the error occured.

In this case, I didn't have a very hard time finding the source of the error even though it was several function calls deeper than what was actually reported. In this case, the exception type and message gave me most of the information I needed. That won't always be the case. How do those of you who are more experienced deal with this sort of error?

comp.lang.c refugee
Tuesday, October 05, 2004

Look at the InnerException property of the System.Exception class.

Christopher Wells
Tuesday, October 05, 2004

Ahh, thank you. In this case I was able to eliminate the problem by getting rid of the late binding (I'd left type information off of a declaration, and I hadn't meant to) but it's good to know how to do that.

Now that you mention it, I remember noticing the InnerException property and thinking that such a thing would've been useful in other languages that I've used.

comp.lang.c refugee
Tuesday, October 05, 2004

*  Recent Topics

*  Fog Creek Home