Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn WPF Binding error into runtime exception. Not working on published Released app

Tags:

c#

wpf

I would like to log the DataBinding errors to a file. I Used the solution presented in this accepted anwser:

How can I turn binding errors into runtime exceptions?

I also tried this: http://msdn.microsoft.com/en-us/library/system.diagnostics.presentationtracesources.aspx

The problem is that it only works while running in the VS IDE. When I publish the app the errors are not caugth.

Does anybody know how to get the WPF Bindind errors and save to a file, by the published app, programatically, during runtime ?

like image 259
Tony Avatar asked Oct 09 '13 14:10

Tony


1 Answers

I used a technique similar to the one described in the first link you provided. It can be resumed by the following steps:

  1. Derive a TraceListener that throws instead of logging
  2. Add your listener to PresentationTraceSources.DataBindingSource

I tested with .NET Framework 4.0, 4.5 and 4.5.1; it works on both Debug and Release configurations.

Please check the complete solution I pushed on GitHub, it includes a demo application and a unit test project.

Exception in Visual Studio

like image 148
Benoit Blanchon Avatar answered Sep 30 '22 08:09

Benoit Blanchon