stack-trace

Use C# attribute to track function call, variables, and return value?

拜拜、爱过 提交于 2020-01-01 05:31:05
问题 In Python, I can use decorators to trace the function call, its variables and return values. It is very easy to use. I just wonder can C# do the same thing? I find out there is a sample code of CallTracing Attribute online. However, it didn't show the result I expected. Does C# attributes have similar concepts as python's decorator? Thanks you and Best Regards! [AttributeUsage(AttributeTargets.Method | AttributeTargets.ReturnValue | AttributeTargets.Property, AllowMultiple = false)] public

How to use Stacktrace to return Error Line Number in vb.net

扶醉桌前 提交于 2019-12-31 22:21:12
问题 I am trying to create some sort of error catching method that will return the error line number. We have an abort email that is sent out when a process aborts that gives us the err.number and err.description but I would like to know where is actually errors out. I know you can do the following: 1: code here 2: code here 3: code here etc. and use ERL to get the number but it would be tedious to type each line out like that. Is there either a way to automatically do this or would it be easier

How do stack traces get generated?

我与影子孤独终老i 提交于 2019-12-31 02:18:04
问题 No single method in a program "knows" where it is on the stack. All it knows is its own little job, and it does that and returns. So when an Exception is thrown and a stack trace is printed, where does this come from? Is there implicitly a separate Thread running alongside of every application in the JVM that's monitoring the state of the program? Or does the JVM itself hold this information and the Exceptions somehow pull that data from it when they are thrown? If either of these is the case

Why are the names of generic types mangled in a .NET stack trace?

Deadly 提交于 2019-12-30 18:26:13
问题 I have an exception being thrown from a C# method, that takes a generic list as a paremeter. private static void DoWork(List<ClassName> a) { } When it throws an exception, the stack trace shows an `1 instead of the class name for the list. Why is this? This is what the stack trace has. ... at DoWork(List`1 a). ... 回答1: The reason why is that the stack trace is generated by the CLR and not C#. Hence it uses CLR type names vs. C# type names. The type names given to generic types in metadata (in

How to get value of arguments passed to functions on the stack?

霸气de小男生 提交于 2019-12-30 07:59:11
问题 Using: traceback.print_stack() I can get: File "x.py", line 20, in <module> y(x) File "x.py", line 11, in y fun(x) File "x.py", line 8, in fun traceback.print_stack() I there any way to get something like this: File "x.py", line 20, in <module> y(x) WHERE x == 1 File "x.py", line 11, in y fun(x) WHERE x == 'str' File "x.py", line 8, in fun traceback.print_stack() I just want to see what arguments was passed to functions. 回答1: You can probably rig something up by using inspect.getargvalues()

How do I get the executing object for a stackframe?

淺唱寂寞╮ 提交于 2019-12-30 04:18:25
问题 When using reflection it is possible to obtain the call stack (apart from that it can be a crude approximation due to JIT optimizations) using System.Diagnostics.StackTrace and examine the StackFrame objects contained. How can I get a reference to the object (the this-pointer) on which a method in a stack frame is executing? I know I can get the MethodBase by calling GetMethod() on the stack frame object, but what I'm looking for is something along the lines of GetObject() (which'd naturally

StackTrace/StackFrame don't return expected info in a production environment

大兔子大兔子 提交于 2019-12-30 01:26:49
问题 I use the following method in my ASP.NET web application to receive the stack trace for an exception: public static void getStackTraceInfo(System.Diagnostics.StackTrace trace) { for (int i = 0; i < trace.FrameCount; i++) { int nLine = trace.GetFrame(i).GetFileLineNumber(); int nCol = trace.GetFrame(i).GetFileColumnNumber(); string methodName = trace.GetFrame(i).GetMethod().Name; } } try { } catch(Exception ex) { getStackTraceInfo(new System.Diagnostics.StackTrace(ex, true)); } It gives me

Inspect the managed stack

限于喜欢 提交于 2019-12-29 08:07:47
问题 A .NET application can get a managed StackTrace that describes which methods were called and holds references to them to get their name, token and signature, and at which IL offset in the method body the call was made. But it does not contain the argument values that were passed to each method. The argument values are in the process's stack memory somewhere for sure, but that's the native representation which may be a bit unhandy and unpredictable to evaluate. There is also the managed stack,

Why does the Stack Trace shows my development files path?

浪子不回头ぞ 提交于 2019-12-28 11:44:13
问题 Visual Studio 2010 SP1, compiled WCF app, put it on a server, and of course it got an error on the first run (what's new), outputted Stack Trace to log file. It's seeing the path to my development environment. Why? Is it because I deployed it as Debug compared to Release or is there something else, or shall I be more careful about outputting Stack Traces regardless? 04/09/2012 03:58:46: Error: Object reference not set to an instance of an object. at App1.Logging.LogMessageToFile(String msg,

How to print full stack trace in exception?

安稳与你 提交于 2019-12-28 08:07:31
问题 For example, in one place... //---------------a try { // some network call } catch(WebException we) { throw new MyCustomException("some message ....", we); } ...and in another place... //--------------b try { // invoke code above } catch(MyCustomException we) { Debug.Writeline(we.stacktrace); // <---------------- } The stacktrace I print, it only start from a to b, it doesnt include the inner stacktrace from the WebException. How can I print all the stacktrace??? 回答1: I usually use the