In my ASP.NET MVC app I'm using a small helper to iterate through all the controllers. This helper is located at a different assembly than my MVC app and I'm referencing to it.
The problem is, that when calling the Assembly.GetCallingAssembly() method in the helper, it doesn't returns the MVC app assembly, but it returns the helper assembly instead. This is not what I'm expecting to get, because all my controllers are living in the MVC app assembly and I need to reflect it.
The view code(MVC app assembly):
<nav>
<ul id="menu">
@foreach(var item in new MvcHelper().GetControllerNames())
{
@Html.ActionMenuItem(
(string)HttpContext.GetGlobalResourceObject("StringsResourse", item), "Index",
item)
}
</ul>
</nav>
The Helper code(independent assembly):
public class MvcHelper
{
public List<string> GetControllerNames()
{
var controllerNames = new List<string>();
GetSubClasses<Controller>().ForEach(
type => controllerNames.Add(type.Name));
return controllerNames;
}
private static List<Type> GetSubClasses<T>()
{
return Assembly.GetCallingAssembly().GetTypes().Where(
type => type.IsSubclassOf(typeof(T))).ToList();
}
}
What am I doing wrong here?