Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting name of entry assembly
Message
De
09/04/2008 10:38:19
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 8.0
Divers
Thread ID:
01307752
Message ID:
01309336
Vues:
6
>>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.
Very fitting: http://xkcd.com/386/
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform