Problems finding classes in namespace
Posted
by Matt
on Stack Overflow
See other posts from Stack Overflow
or by Matt
Published on 2010-04-11T02:37:04Z
Indexed on
2010/04/11
4:13 UTC
Read the original article
Hit count: 340
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.
© Stack Overflow or respective owner