I am trying to implement somewhat more sophisticated error handling. To achieve my goal, I need to filter out non-user code methods (frames) from curent StackTrace.
In ASP.NET typical StackTrace as you can probably guess the are many methods that are quite irrelevant for debugging purposes as they are outside of the user code. Visual studio gives you option to filter out this non-user code (frames) so I am guessing its possible. However after about 30 minutes of exploring methods and properties of StackFrames (and methods, modules, assemblies, … ) I couldnt find any that could be used to identify “system” frames.
I have ended up with manual specification of which modules I want to log (module is part of assembly, in my case 1:1).
Is there any better way to do this? Simply include everything outside core ASP.NET.
StackFrameclass has theGetMethod()member function, from retrievedMethodBaseobject.If all you need is a naive filter you may do one of these:
AssemblyCompanyAttributeand filter assemblies made by “Microsoft Corporation”). This is better than previous method because sometimes I saw libraries which put their own types insideSystemnamespace.If you need something more you can get the module (
MethodBase.Module) where that method is defined. Now you have two options:Module.Assemblyproperty, build anAssemblyNameobject withAssembly.FullNamethen check the public key forAssemblyName.KeyPairproperty, it must match your public key token (simply compare withGetExecutingAssembly()).Please note that not all system assemblies have the same public key token (even within the same Framework version) so you must collect and check a list of keys (just browse
c:\windows\assemblyto read them). A good approach could be to check for public key and then apply a second filter usingAssemblyCompanyAttribute.