Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting name of entry assembly
Message
 
À
02/04/2008 16:41:01
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:
01307975
Vues:
9
>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

RCS Solutions, Inc.
Blog
Twitter
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform