1

I have a complicated WPF application that is used on some kind of a PA system. It shows videos time to time and sometimes it does play music and different text messages on the screen.

Structure is pretty straight forward. There is a server that has 2 methods. SetMessage("String"); and GetMessage("String");

Client once in 5 seconds connects to the server via HTTP binding on WCF and pulls GetMessage(). Admin app connects to the server and calls SetMessage().

In the App.xml.cs i have a handlers for CurrentDomain_UnhandledException, OnDispatcherUnhandledException, TaskScheduler.UnobservedTaskException and application.Current.DispatcherUnhnandledException. All of them suppose to do nlog and continue operation.

There is one page in the App that uses Media element to play short videos. Time to time after video was played I'm getting app crash.

EventType : clr20r3
P1        : Client.exe
P2        : 0.0.2.0
P3        : 5226863e
P3        : mscorlib
P5        : 4.0.0.0
P6        : 4ba1da6f
P7        : 219
P8        : 10
P9        : system.invalidoperaionexception

Now that's all cool. Yet the problems are:

  1. Despite of 4 different exception handlers I'm still geting the exception
  2. I'm not able to debug on the client computer
  3. Error is random but happens after I played the video.
  4. Code to stop and start the video is in Dispatcher.Invoke(new Action).
  5. I might just leave the page and switch to another one before doing stop of the video.

Looks like I'm just violating some access and trying to change something in code from another thread.

Funny thing is that I tried to do ILDasm and find that P7:219 and there is none in the code.

Is there any way to catch that freaking exception?

(I actually spend around 30 mins, trying to find any similar problems here, but all the solutions already applied in my code)

Thanx for help.

NewRK
  • 409
  • 3
  • 15
  • wrap the code throwing the exception (probably in that `new Action` you're passing to the dispatcher) in a try/catch and call `Exception.ToString()` on the exception object in the catch block. Save that somewhere. Dump it to disk, whatever. Remember, also, that exceptions crossing thread boundaries will take down your entire application. But without the exception details ... who knows? –  Sep 12 '13 at 18:36
  • Yeah, thanks for that, @Will. I will try. Yet that's the problem, looks line I'm between threads there and I can't actually tell what and where throwing the bleep. I actually don't really know which one of the peices throwing the exception. – NewRK Sep 12 '13 at 18:39
  • Your first step is to track down that exception object. Wrap any code you suspect of throwing with it. Once you have the full exception details (You'll get that from ToString()), [edit] and add the info here. Or you may find your solution. –  Sep 12 '13 at 18:45
  • Don't you have a crash dump? http://stackoverflow.com/questions/3263813/a-process-crashed-in-windows-crash-dump-location – rene Sep 12 '13 at 18:45

2 Answers2

1

I think that you are somewhere starting a new thread with it's own dispatcher
please take a look at the remarks given by msdn on this link
http://msdn.microsoft.com/en-us/library/system.windows.application.dispatcherunhandledexception.aspx

DispatcherUnhandledException is raised by an Application for each exception that is unhandled by code running on the main UI thread. If an exception is not handled on either a background user interface (UI) thread (a thread with its own Dispatcher) or a background worker thread (a thread without a Dispatcher), the exception is not forwarded to the main UI thread. Consequently, DispatcherUnhandledException is not raised. In these circumstances, you will need to write code to do the following: Handle exceptions on the background thread. Dispatch those exceptions to the main UI thread. Rethrow them on the main UI thread without handling them to allow DispatcherUnhandledException to be raised.

just for information you can't catch a bug with it's own dispatcher even if you are implementing all this exceptions handlers

Hope this can help you

BRAHIM Kamel
  • 13,492
  • 1
  • 36
  • 47
  • Well, that's interesting. My main problem was in the fact, that I was not able to find trace stack. And guess what? I found it. Yet not in WER folders, but randomly looking the event log. And it was there - bam! So thanks, you showed the right way. I was scrambling threads too much and improperly used thread pool. – NewRK Sep 13 '13 at 15:44
0

Well it was easy after all.

I didn't had a trace stack to figure out the problem. I tried to do nlog, WER and many other things but I was not getting real trace stack.

And when, just out of interest I decided to check Windows Logs I found that after log of the error Windows did log the stack trace! It allowed me to find the error in a seconds.

Problem was in exception generated in the work in a threadpool.

NewRK
  • 409
  • 3
  • 15