Can PropertyInfo.DeclaringType really ever be null?

It can be null if the property is defined in a module. In C# you cannot define such methods and properties without reflection (see PropertyBuilder). However, if you reference a VB.NET assembly, it can have such members.


The PropertyInfo.DeclaringType property is inherited from MemberInfo.DeclaringType and from documentation:

If the MemberInfo object is a global member (that is, if it was obtained from the Module.GetMethods method, which returns global methods on a module), the returned DeclaringType will be null.

So, warning seems fine in that case.