locked
DependencyObject is ambiguous errors

    Question

  • I'm developing a component with a number of Dependency Properties. VS2012 Intellisense is showing this error for every call to GetValue, SetValue, but the solution compiles just fine. Is there a way to get ride of these warnings? My component inherits from Control, but if I try fully qualifying the calls I get the same error. 

     IntelliSense: base class "Windows::UI::Xaml::DependencyObject" is ambiguous ...

    Monday, February 11, 2013 4:12 AM

Answers

  • You create a UserControl called MyUserControl.

    In its MyUserControl.g.h file (the generated header that is built as part of parsing the XAML), the MyUserControl class derives from ::Windows::UI::Xaml::Controls::UserControl.

    The UserControl class derives from Windows::UI::Xaml::Controls::Control.

    In your MyUserControl.h file (the non-generated header that you modify to add things to your class) you specify that MyUserControl should derive from Control. This introduces an ambiguity since you did not specify virtual inheritance and the MyUserControl class already derives from Control by way of UserControl. As such you are trying to derive from the same class (Control) twice, which is what gives the error. Remove the ": public Control" from your class definition in MyUserControl.h and the ambiguity disappears (and everything compiles).


    XNA/DirectX MVP | Website | Blog | @mikebmcl

    Saturday, February 23, 2013 11:20 AM

All replies

  • Do you have another "Windows" namespace that could be conflicting? Try fully qualifying your call from the root:
    ::Windows::UI::Xaml::DependencyObject
    --Rob
    Monday, February 11, 2013 4:16 AM
    Owner
  • Thanks for the reply, Rob

    I tried that, but I still get the same error.

    Monday, February 11, 2013 4:28 AM
  • If you're still running into this can you reproduce this in a minimal repro sample you can upload to your SkyDrive for us to look at?

    --Rob

    Saturday, February 23, 2013 2:39 AM
    Owner
  • Thanks, Rob

    Sample solution is at http://sdrv.ms/YkwswC

    Saturday, February 23, 2013 5:55 AM
  • You create a UserControl called MyUserControl.

    In its MyUserControl.g.h file (the generated header that is built as part of parsing the XAML), the MyUserControl class derives from ::Windows::UI::Xaml::Controls::UserControl.

    The UserControl class derives from Windows::UI::Xaml::Controls::Control.

    In your MyUserControl.h file (the non-generated header that you modify to add things to your class) you specify that MyUserControl should derive from Control. This introduces an ambiguity since you did not specify virtual inheritance and the MyUserControl class already derives from Control by way of UserControl. As such you are trying to derive from the same class (Control) twice, which is what gives the error. Remove the ": public Control" from your class definition in MyUserControl.h and the ambiguity disappears (and everything compiles).


    XNA/DirectX MVP | Website | Blog | @mikebmcl

    Saturday, February 23, 2013 11:20 AM
  • Thanks Mike! That did the trick. I believe that did the double inheritance from Control because of some sample code I was deriving from. I would be nice if the compiler returned a more targeted error ;-)
    Saturday, February 23, 2013 4:11 PM