RadDatePicker with Unity.WebForms

2 posts, 0 answers
  1. Don
    Don avatar
    1 posts
    Member since:
    Nov 2014

    Posted 20 Nov 2014 Link to this post


    I am using Unity.WebForms to enable dependency injection in my WebForms app. Whenever I attempt to access a page that contains a RadDatePicker, I get an exception telling me "The type CalendarPopupButton has multiple constructors of length 1. Unable to disambiguate."

    Can you help me understand why Unity is not playing well with the Telerik tools? Thank you bery much,

  2. Kyle
    Kyle avatar
    1 posts
    Member since:
    Aug 2012

    Posted 23 Nov 2014 in reply to Don Link to this post

    Without knowing the particulars of how your code is written, here is my best guess at what is going on...

    Unity likes to be helpful and will try to resolve a dependency chain if it can, even if one of the types in that chain hasn't already been registered within the container. What this means is that if class A depends on class B and you have only registered class A within the container, Unity will attempt to construct a new instance using reflection to see if it has enough information to do so. It will look for a default/parameter-less constructor or any constructor whose parameter types are already registered within the container. Failing that, it attempts the same process with each of the parameters of the class B constructors until it either builds up a full dependency tree or fails.

    There are 2 potential solutions that I can think of really quickly:

    1) Register the RadDatePicker in the Unity container and specify how it should resolve the constructor parameters. See the Unity documentation for how you register a type that doesn't have a default/parameter-less constructor for more information.

    2) Fork the code for Unity.WebForms (https://bitbucket.org/KyleK/unity.webforms) and edit line 92 of the UnityHttpModule.cs class the include a check for the 'Telerik' namespace in addition to the 'System' namespace. This will prevent Unity.WebForms from attempting to dependency inject anything from Telerik (unless you explicitly register it with the container).

    Hope that helps!
  3. DevCraft R3 2016 release webinar banner
Back to Top