I have an action being executed inside of a portable area that needs to get information about the Assembly that called it. The portable area is in project Core and is referenced by client app Client.
GetAssembly and GetExecutingAssembly both return the Core assembly:
// Both are Core
assembly = Assembly.GetAssembly(GetType());
assembly = Assembly.GetExecutingAssembly();
My next thought was to use GetCallingAssembly, but that brings back Anonymously Hosted DynamicMethods Assembly.
assembly = Assembly.GetCallingAssembly();
The only other option is GetEntryAssembly, which is just null:
assembly = Assembly.GetEntryAssembly();
What I want to do is get a reference to the Client assembly using the built-in framework. Obviously, I could use some fancy dependency injection or some other less sophisticated method to get that information to this action; however, I’m wondering if there’s a better built-in way to do this.
Clarification: What I’m trying to get here is version information of the client Assembly. I want each client to have access to a VersionInfo partial that lives in the Core area and adds build version information to a rendered page. So, the action in Core needs to know the Assembly that called it so that it can reflect out the version info.
After much effort and many tears, I’ve determined that DI is going to be the best way to do this. Why?
Some Info on Portable Areas
After some research and observation, it appears that portable areas run in their own sub-instance of MVC. My attempt to call a partial view from my portable area lives in the view of my client application:
If I pull out a stacktrace at the
VersionAction inCore, I get:Since all of the controller code in my Client application has already executed, there’s not even a reference to that assembly in the stack trace any longer. I also tried adding an
Assemblyarg to theVersionsaction, a la:but the result from that is
App_Web_xq4cmhcy, obviously a generated assembly.So, really the only option left is to add a DI container that gets initialized in the Global.asax of every client application with the executing assembly, which can then be read by the Core method.