I'm interpreting an exception report from a C# Windows Phone app. A method throws a NullReferenceException
. The method goes:
public void OnDelete(object o, EventArgs a)
{
if (MessageBox.Show(Res.IDS_AREYOUSURE, Res.IDS_APPTITLE, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
m_Field.RequestDelete();
}
It's consistent with m_Field
being null - there's simply nothing else there that can possibly be null. But here's the mysterious part.
The GetILOffset()
from the StackFrame
from the StackTrace
for the exception object returns 0x13. The MSIL for the method, as shown by ILDASM, goes:
IL_0000: call string App.Res::get_IDS_AREYOUSURE()
IL_0005: call string App.Res::get_IDS_APPTITLE()
IL_000a: ldc.i4.1
IL_000b: call valuetype (...) System.Windows.MessageBox::Show(...)
IL_0010: ldc.i4.1
IL_0011: bne.un.s IL_001e
IL_0013: ldarg.0
IL_0014: ldfld class App.Class2 App.Class1::m_Field
IL_0019: callvirt instance void App.Class2::RequestDelete()
IL_001e: ret
Here's what I don't understand. If the offset is indeed 0x13, that means the ldarg
line causes the exception. But the command is documented as not throwing any exceptions. It's callvirt
that should throw, isn't it? Or is the offset relative to something other than the method beginning? ldfld
can also throw, but only if the this
object is null; that's not possible in C# AFAIK.
The docs mention that debug info might get in the way of the offset, but it's a release build.
The DLL that I'm examining with ILDASM is exactly the one that I've shipped to the Windows Phone Store as a part of my XAP.