TLDR: How can I check DeclaringType for null without causing a further cascade of problems in the function?I have a C# LINQ query that uses reflection to list all Areas, Controllers, and Actions in my MVC Project. It appears to work correctly. I have not encountered any actual errors in the output.Resharper, however, is declaring a possible null reference warning (see screenshot). It is not a false flag because there is always the possibility that Type MembershipInfo.DeclaringType could be null. I went with Resharper's suggestions of fixing the code (Check expression for null or Use Conditional Access). Neither approach helped.I have even tried splitting apart the function and running a for-each loop to detect and change null into an empty string, but because even that for-each loop depends on a possibly null variable, I still get the same Resharper warning.My workaround is to simply ignore the warning, but I was wondering if there is a way to check for null that doesn't cause even more cascading issues? If this were T-SQL I could easily place a case or where statement in the query; alas, I am unable to work that approach here. private static IEnumerable<RwsPagelistViewModel> ActionLevelPermissionList(){    var projectName = Assembly.GetExecutingAssembly().FullName.Split(',')[0];    var asm = Assembly.GetAssembly(typeof(MvcApplication));    var list =         asm.GetTypes().        SelectMany(t => t.GetMethods(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public))        .Where(d => d.ReturnType.Name == ActionResult)        .Select(n => new        {            Area = n.DeclaringType.Namespace.ToString()            .Replace(projectName + ., )            .Replace(Areas., )            .Replace(.Controllers, )            .Replace(Controllers, ),            Controller = n.DeclaringType != null ? n.DeclaringType.Name.Replace(Controller, ) : null,            Action = n.Name,            Attributes = string.Join(,, n.GetCustomAttributes().Select(a => a.GetType().Name.Replace(Attribute, ))),            AuthorizedRole = AuthorizedRole(n.CustomAttributes)        })        .Where(z => z.Attributes.Contains(RoleAuthorize))        .Select(y => new RwsPagelistViewModel            {                Area = y.Area,                Controller = y.Controller,                Action = y.Action,                AuthorizedRole = y.AuthorizedRole            });    return list;}
Addressing System.NullReference Resharper warning in function
c#;linq;reflection