WPF Recursive call to Automation Peer API is not valid

I've bypassed the problem on my end by turning off Automation on the grid control. I found that the problem was unique to the WPF Toolkit control, but I was having problems transitioning to the 4.0 official release DataGrid (unrelated to this question.)

So instead, I derive the class from the WPFToolkit and supply this override:

protected override AutomationPeer OnCreateAutomationPeer()
{
   return null;
}

Maybe someone can tell us if this is a good idea or not.


I had exactly the same error. However for me it was strange that the same application was working fine on my laptop and caused the error on my desktop PC. The same OS, the same architecture and the same Visual Studio with the same add-ons.

So I checked references to WPFToolkit on my laptop, where everything was fine. It pointed to:

C:\Program Files (x86)\WPF Toolkit\v3.5.40619.1\WPFToolkit.dll

then I checked reference on my desktop, it pointed to:

C:\Program Files (x86)\WPF Toolkit\v3.5.50211.1\WPFToolkit.dll

As you can see I had two different versions of WPFToolkit installed. I copied whole folder from my laptop to my desktop, changed references from version v3.5.50211.1 to v3.5.40619.1 and the problem was resolved. No more exceptions. Hope this will help someone as well.