Sunday, November 26, 2006

I encountered a rather annoying reflection exception that caused WPF dead in it's tracks during binding which I thought might be nice to share here.

The problem arises when you bind against a property and WPF (or rather: reflection) can not determine which property you actually mean. This situation can occur when you have a property on a base class and you redefine (using the 'new' keyword) that property on a class that inherits from the base class. Here is some pseudo-code:

 

public class mySpecialisation<T> : myBase { public new T myProperty { get { return (T)base.something; } } } public class myBase { public object myProperty { get { return something;} } }

As you can see, the above situation might be a convenient way to construct your classes. However, it will throw an ugly exception.
The obvious way to work-around this problem, is to make the property on the baseclass private or protected. However, in my case, I needed to get the the property through the baseclass as well. So I renamed the property in the inheritor and got rid of the exception. Kind of disappointing though!

Wednesday, November 29, 2006 11:50:16 AM (Romance Standard Time, UTC+01:00)
Very disappointing.

Grtz, Da Chrisis :D
Christiaan
Thursday, December 28, 2006 8:22:30 PM (Romance Standard Time, UTC+01:00)
Even worse is when the base class is in a different assembly. Not only do you get the reflection exception, but the assembly of the descendant class you're binding to will get locked and you have to restart Visual Studio.
Nolan Egly
Wednesday, September 19, 2007 5:30:10 PM (Romance Standard Time, UTC+01:00)
Good post!. I'm having the same problem, did you find a solution eventually ?
Thanks
Thursday, September 20, 2007 10:21:37 AM (Romance Standard Time, UTC+01:00)
Here you go a solution:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2166578&SiteID=1
Thursday, September 20, 2007 8:33:00 PM (Romance Standard Time, UTC+01:00)
Hey Carlos,

thanks for posting back. Great find!
Ruurd
Name
E-mail
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):