Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can I have a DLL tell what EXE is call it?
In one of the DLL's properties I want to read from the calling EXE's app.config but can't figure out the ____.My.MySettings.

Here is my code so far but the CallingProcName is returing "ctor"

VB
Public ReadOnly Property ISLogConnectionString As String
     Get
         Dim ScriptDefaultMode

         Dim StackTrace As New StackTrace()
         Dim StackFrame As StackFrame = StackTrace.GetFrame(1)
         Dim CallingProcName = StackFrame.GetMethod().Name


         ' what settings server are we going to look to first?
         Try
             ' look for an App.Config Setting of zDefaultRing (ISScriptingTemplate) in the EXE's ApplicationSettings
             Dim exeConfig As Configuration
             exeConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)

             Dim sectGroup As ApplicationSettingsGroup
             sectGroup = exeConfig.GetSectionGroup("applicationSettings")

             Dim sect As ClientSettingsSection
             sect = sectGroup.Sections(CallingProcName & ".My.MySettings")

             Dim elm As SettingElement
             elm = sect.Settings.Get("zDefaultRing")
             ScriptDefaultMode = elm.Value.ValueXml.InnerXml


.
.
.
Posted

1 solution

You can get all detail of the current call stack using the class System.Diagnostics.StackTrace. Please see:
http://msdn.microsoft.com/en-us/library/system.diagnostics.stacktrace.aspx[^].

You can also find out the entry assembly of the code executing the following code:

C#
System.Reflection.Assembly entryAssembly = System.Reflection.Assembly.GetEntryAssembly();

// and this is its main executable module file:
string exeFile = entryAssembly.Location;


Please see:
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx[^].

—SA
 
Share this answer
 
v2
Comments
VJ Reddy 19-Apr-12 20:10pm    
Succinct and to the point. 5!
Sergey Alexandrovich Kryukov 19-Apr-12 20:30pm    
Thank you, VJ.
--SA
Manoj Kumar Choubey 20-Apr-12 0:38am    
my +5
Sergey Alexandrovich Kryukov 20-Apr-12 11:02am    
Thank you, Manoj.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900