NDepend can't find attribute from mscorlib in rule

51 views Asked by At

I'm trying to exclude interop structs (structs having explicit struct layout) from getting "dead field" warnings from NDepend. My query with the added attribute filter looks like this:

warnif count > 0
from f in JustMyCode.Fields where
  f.NbMethodsUsingMe == 0 && 
  !f.IsPublic &&    
  !f.IsLiteral &&    
  !f.IsEnumValue &&  
  f.Name !=  "value__" &&       
  !f.ParentType.HasAttribute("System.Runtime.InteropServices.StructLayoutAttribute") &&  
  !f.IsGeneratedByCompiler

But NDepend will complain that StructLayoutAttribute is not a valid type name. mscorlib is listed under <FrameworkAssemblies> in the ndproj file.

I notice many rules in the default rule set have AllowNoMatch() when using system types from mscorlib. For example, the rules regarding DllImport use

 m.HasAttribute ("System.Runtime.InteropServices.DllImportAttribute".AllowNoMatch()) &&

What does that mean? Is that there to prevent the rule from choking when the user hasn't referenced mscorlib in the <FrameworkAssemblies> list? Or am I misunderstanding something about how NDepend actually resolves third party types? I add .AllowNoMatch() there is no longer a syntax error, but of course the rule now reports my struct fields as unused.

0

There are 0 answers