"Dependency attribute is not valid for this ad type." mistake

Why am I getting such a message?

Dependency attribute is not valid for this ad type. It is valid only for 'assembly' declarations.

public partial class MainWindow : Window { private OverviewViewModel _vm; [Dependency] public OverviewViewModel VM { set { _vm = value; this.DataContext = _vm; } } 
+7
source share
3 answers

You are probably using the wrong attribute: DependencyAttribute

Indicates when the dependent should be loaded by the referenced assembly [...]

and can only be applied to assemblies (and not to the properties you are trying), for example:

 [assembly: Dependency(/*...*/)] 
+5
source

Attributes are allowed to declare what they can access (through the AttributeUsageAttribute attribute). The default value is anything, but in this case it is “assembly”, which means: you can only apply it at the assembly level, which you do with:

 [assembly:Dependency(...)] 

If this is your own attribute, check the AttributeUsageAttribute attribute associated with it and make sure that it includes properties (using the pipe | to apply "or").

If this is not your attribute, double check the intended use - you may use it incorrectly.

+4
source

Try enabling getter:

 private OverviewViewModel _vm; [Dependency] public OverviewViewModel VM { set { _vm = value; this.DataContext = _vm; } get { return _vm; } } 

code>

0
source

All Articles