Troubleshooting WPF / Silverlight XAML databinding? - wpf

Whenever I am doing XAML, I tend to run into problems with databinding. It is often small issues, such as misspelling a property name.
My problem is, that I don't seem to receive any errors or warnings when I am trying to bind to a property that does not exist. It would be nice to get a warning, either at compile or runtime, about my errors.
Is it possible to get a warning about wrong databinding expressions ? What do you do to troubleshoot when your data does not appear as expected ?

WPF will write warnings about problems in data binding to the Visual Studio "Output" window

This blog post, How can I debug WPF bindings? helped me learn why my Binding was failing.
I've accepted the other answer to this question because it is technically correct, but I wanted to include the link above in this question, for future reference.

Related

System.Runtime.RemotingException in simple XAML file

I have a WPF application which is giving me a very very annoying error
System.Runtime.Remoting.RemotingException
[12068] Designer process terminated unexpectedly!
The number between [] changes each time
The XAML is very simple
<UserControl x:Class="STC.Reports.ReportGenerator.Views.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
</UserControl>
This has wasted me hours and hours
Does anyone know anything that could help?
I cant get any more information than that above
Even though I have told VS to break on these Exceptions it doesnt
I have also tried to attach another VS and that makes no difference
I have repaired my installation of VS (2012 Professional)
I have also updated to Update 3
This is even happening when I create a brand new WPF application
Everything seems fine initially, then VS just hangs and the remoting error occurs
Paul
What kind of message are You getting?
If it is a Messagebox when You try to use designer - it is a known issue since VS2010 as far as I remember. It is frequently caused by a video card or its driver, so the easiest way is trying to update your video driver or use some older version. Sometimes that help.
The other way is not to use built-in designer. As for me, I wite pure xaml and it seems to be more convenient and faster way of development. Or, if You like visual UI - You may use Blend. AFAIK it is a part of VS2012 now.
I had this error occur for all windows/controls in a project, even if they were brand new empty windows. I had a markup extension causing a design-time exception (with no indication of this from Visual Studio) and I would get this designer error if I used the markup extension in any project resource dictionaries.
Old post but might be useful for future developers who run into this kind of problem.
I had this exact behaviour. Turned out to be a problem related to my viewmodel. At runtime everything works, but at design time VS will try to load the viewmodel standalone and things got haywire. My viewmodel depended on some global object which I created elsewhere at application startup. Loading the viewmodel standalone creates a exception since the global object was missing.
Quite easy to detect actualy. Just test your viewmodel by instantiating it yourself from code. If it fails VS won't be able to run the designer as well and as you see VS unfortunately won't tell you what happened.

Unable to use usercontrols in my project

I'm working on a WPF solution. For some odd reasons, I'm getting the error "The type '...' was not found. Verify that you are not missing an assembly reference..." every time I add a usercontrol/custom control through XAML. I did build the solution, had the namespace declaration for XAML, made sure I had the correct assembly name, and made sure that the usercontrol itself doesn't contain any errors.
What's even weirder is that, when I ignore the errors and add the controls manually through the XAML editor (heck, even InteliSense in the XAML editor works), then build & run it, everything works (I'm guessing this means that there's no problem with the solution itself)
The controls show up in the toolbox, but I can't add it through the designer. As I stated, adding through the XAML editor/in code behind works, but it's really inconvenient. Adding through the XAML editor also raises the error, and stops the designer from loading, so it's even more annoying. Adding through code behind is just inelegant, and makes it hard for debugging.
EDIT: Opening the solution on a different computer doesn't solve the problem, so it's not a problem caused by Visual Studio. Also tested moving everything to a new project, still doesn't work, which means it's not a problem with the configurations, likely a problem with the code. If then, how come it builds & runs, and even IntelliSense works and the designer doesn't?
Okay...nevermind, it's because I built it for x64, and apparently the designer just doesn't work with that since it's x86. Using "AnyCPU" seems to work.

Finding if databinding failed in code?

I am wiring up a binding in code (NOT in XAML).
Is there any way of determining whether the binding path is valid? The obvious candidate is IsDataBound property, but this is always true even if the path is wrong.
Currently I am fudging it by supplying a fallback value and testing for that, but is there a better way?
If you don't mind upgrading your project to Silverlight 5, check out the Silverlight 5 RC. With SL5 debugging databinding has become a breeze since it enables you to set breakpoints inside your XAML code where the binding happens.
Check out this article for a full overview how this works.
The Output-window of Visual Studio is a good place to start, for a more indepth guide on debugging bindings see this MSDN article.
I guess you could use a ValueConverter, which you can add pretty easily in code to your binding and will let you evaluate what is going on between the source and target properties.

Out of Memory error in Visual Studio 2008, opening WinForms designer. How to solve?

I'm using Visual Studio and while fiddling around with a custom control, I started to get an out of memory error.
The stack trace is not helpful - it's just a bunch of frames doing Reflection and so on.
How can I fix this?
There was a problem in the constructor of the custom control.
For some reason, calling Bitmap.MakeTransparent() on a bitmap that doesn't have a transparent bit set, causes an out of memory error.
This was being reported in the designer, but without any of the actually relevant stack trace.
The solution was to comb through the custom control and make sure the constructor could never through an exception. One approach is to surround the constructor logic in the control with a try...catch, and report the error with Console.WriteLine. You'll see it at runtime, with full stack trace.
Note: I searched the intertubes and saw a number of questions asking about similar problems, but nothing definitive for an answer. So I put this question + answer here hoping it might help someone else.

Debugging Silverlight Bindings

I have a binding in Silverlight that is causing my application to exit. An unhandled exception is not throw; I just get a white screen.
I am not seeing anything from the binding engine in the output window.
Does anyone have any ideas for debugging this issue?
I suggest you use Karl Shiflett's Glimpse for Silverlight for that.
Also, I just "heard" Laurent Bugnion on twitter recommend using a mock Converter on a binding to figure out why it's failing. That's a good idea in case you're unsure as to what values are being fed to the binding.
Dave, dont get too excited about the XAML debugging in SL5. I have been building projects for a few weeks now in SL5 and all I can say is that the XAML debugger will break after very little use and all you will get back is the ridiculous error message saying that the PDB's cant be found. I have reset my VS2010 setting numerous times and still the debugger remains crippled. I have spend days if not weeks trying to get to the bottom of the cause and as usual there are no support documents or help sites for this issue. Debugging Silverlight databindings is a black box scenario and a huge weakness in this technology. There is no way of knowing what the XAML parser is doing or not doing as the case may be. I have just had to scrap a project because of a total failure of the bindings in the View. The VM is preforming correctly by all bindings on the view fail. People will tell you that the output window in VS2010 will indicate the binding errors. My experience is that you can have total failure of bindings and NO errors will be shown in the output window. If you get into this scenario there is simply no solution that I am aware of and even the bug ridden XAML debugger wont be able to help you.

Resources