>>I am trying to make a utility library that reports exceptions. When I call the method, I want to get the calling application's name. In Winforms, I can get this by using Assembly.GetEntryAssembly. This same method doesn't work for Webforms. Anybody know a way to consistently do this in .NET? Thanks!
>
>Something like this might work:
>
>
>System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace();
>System.Diagnostics.StackFrame[] frames = trace.GetFrames();
>foreach (System.Diagnostics.StackFrame stackFrame in frames)
>{
> //stackFrame.GetMethod();
> //stackFrame.GetMethod().DeclaringType.FullName;
>}
>
>
>You could also just call trace.GetFrame() with an index to get a specific method on the stack.
>
>If you're C# challenged, the VB might look like this:
>
>
>Dim trace As System.Diagnostics.StackTrace = New System.Diagnostics.StackTrace()
>Dim frames As System.Diagnostics.StackFrame() = trace.GetFrames()
>For Each stackFrame As System.Diagnostics.StackFrame In frames
> 'stackFrame.GetMethod();
> 'stackFrame.GetMethod().DeclaringType.FullName;
>Next
>
Paul,
I am finally getting back to this - sorry for the delay.
It seems this returns a collection of StackFrames. I can iterate through the collection and see the assembly.classname value that I need. The problem is - I don't know how to programatically find exactly which StackFrame I need before it dives into the system classes.