Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
674 views
in Technique[技术] by (71.8m points)

c# - NullReferenceException, no stack trace... where to start?

I have a WPF audio application.

Occasionally (and even in the debugger) I'm seeing a NullReferenceException which carries no stack trace information with it.

How can one start debugging such an issue?

Some background:

I'm P/Invoking functions in WinMM.dll which involves registering a callback when calling waveOutOpen

    [DllImport("winmm.dll")]
    public static extern MmResult waveOutOpen(out IntPtr phwo, IntPtr uDeviceID, WaveFmt pwfx, WaveCallbk dwCallback, IntPtr dwInstance, int fdwOpen);

This has proved difficult to get stable, especially at the point where I call waveOutClose, and immediately call waveOutOpen again (usually to change the output format).

I suspect that the problem may be related to the calls I've been describing above (although on so little knowlege, I could be completely off-target).

Reproducing the problem is currently proving elusive, although I can supply a build to a user who is fairly consistently seeing this problem. I might try to speed up the operations that are causing the problem to the point where reproducing the problem in the debugger is more of a certainty.

With regards to the debugger, I haven't tinkered with any of the settings (including Enable unmanaged code debugging) or any of the Debug -> Exceptions... settings. To be honest, I'm fairly clueless about what's on offer here, so any hints are welcome.

How might an exception not have a stack trace? Have you seen this before? Help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The most helpful thing you can do in the debugger is instruct it to break on a first-chance exception (Debug -> Exceptions):

VS Exceptions window

This will cause a break into the debugger at the exact point a NullReferenceException is thrown, which is pretty much the best you can ever hope for while debugging.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...