I am trying to find all of the types in the Models namespace within an ASP.NET MVC assembly from within a testing assembly. I was trying to use LINQ to find the relevant set for me but it is returning an empty set on me. I am sure it is some simple mistake, I am still relatively new to LINQ admittedly.
var abstractViewModelType = typeof (AbstractViewModel);
var baseAssembly = Assembly.GetAssembly(abstractViewModelType);
var modelTypes = baseAssembly.GetTypes()
.Where(assemblyType => (assemblyType.Namespace.EndsWith("Models")
&& assemblyType.Name != "AbstractViewModel"))
.Select(assemblyType => assemblyType);
foreach(var modelType in modelTypes)
{
//Assert some things
}
When I reach the foreach I receive a Null reference exception.