Methods overloading problems - "An item with the same key was already been added"

Jul 9, 2011 at 1:35 AM

Hello,

When inheriting from ViewModelBase it seems that the class cannot include methods overloading. Meaning you cannot create two methods with the same name but with different parameters.

Is there a fix for that ?

Sincerely,

Eran.

Coordinator
Jul 11, 2011 at 10:41 AM

I am guessing that the problem is in the code that indexes everything during reflection-time, is that correct?  Can you give an example with the error that you receive?  Please note that the source is available and I am happy to take patches.

Thanks,

Brian

Jan 12, 2012 at 5:57 AM

I ran in to the same problem.  To reproduce add the following overloaded methods to the class ViewModelSupportTests.ActiveViewModelTests.GetterSetter_By_String

public void Dummy(string s) { }

public void Dummy(int n) { }

Run the tests and I get 9 failures.

The fix that worked for me is to change ViewModelBase.MapDependencies<T>.  The first line reads

var dependencyMap = getInfo().ToDictionary(

change this to

var dependencyMap = getInfo().Where(p=>p.GetCustomAttributes(typeof(T), true).Any()).ToDictionary(

This limits the dictionary to only have methods which actually are marked with the DependsOnAttribute

Tests all pass now.

If you add a DependsUponAttribute to either of the Dummy methods then 5 tests fail.  I don't know how to fix this.