C# Getting Parent Assembly Name of Calling Assembly

Bohica69

Gawd
Joined
Jul 12, 2005
Messages
676
I've got a C# ASP.NET app that I'm working on. There are three assemblies involved - the assembly of the ASP.NET app itself, a second assembly that the app uses, and a third assembly that's used by the second one.

So the calls go like this:
ASP.NET Assembly ------> SecondAssembly---------> Third Assembly.

What I need to do in the third assembly is get the name of the ASP.NET Assembly that called the second assembly.

Assembly.GetExecutingAssembly().ManifestModule.Name returns the name of the Second assembly.

Does anybody know if there is a way to get to the assembly name of the ASP.NET Assembly?

I can't change the ASP.NET assembly right now (it's deployed to production and we don't want to update it right now for various reasons). I'd rather not do any HTTP Context dependent things in the Third Assembly as we are trying to write the third assembly to be used by windows and ASP.NET apps with no changes.

Any help would be appreciated.

Thanks
Rick
 
So you have something like:

MyAspNetApp calls
MyAspNetHelperlibrary calls
MyDbWrapperLibrary

It's just a matter of creating a StackTrace and walking that, looking at the Assembly that each stack frame comes from. Why are you trying to do this though? Changing behavior based on the caller can lead to strange bugs.
 
MS - Your description is very close.

What we have is
MyASPNetApp Calls
MyCommonControlsLibrary Calls
MyConfigSingleton.

What we are trying to do is get our configuration information out of some xml files and into a database. We have several portals that share configuration information, and the current method of storing the configuration information is in XML files scattered about - Not in the application config. We have more than one production web server, and as we are trying to move apps to production, introduce new features etc, invariably a config file get's moved to the wrong spot, or the wrong file get's moved, etc, and we have problems - many of which aren't seen immediately.

So we are moving the config information into a db, and will be calling a singleton to get the config info from the db. We are also architecting the singleton so we can write some Windows helper apps using it, and get the same config values (where needed) as the web apps. So the behaviour isn't changing, just what config values are pulled from the database.

We would change the MyASPNetApp to call the MyConfigSingleton directly, but don't want to do a release of MyASPNetApp at this time, - but we can change MyCommonControlsLibrary at this time, and MyASPNetApp is already calling it for configuration information - so we just wired up MyCommonControlsLibrary to the MyConfigSingleton under the covers, and MyASPNetApp is never the wiser.

As we go forward, when we DO do our next release of MyASPNetApp, this all becomes a moot point, since we will change it to call the configuration singleton directly.

Thanks for the information about the stack trace - that's the conclusion I had come to, but wanted to make sure I hadn't overlooked something.
 
Back
Top