سؤال

i have a c# windows application (developed in Plugin Architecture) , i want to log all unhandled exception from my application. i am able to catch all the Exceptions.

i want to read the File name and the line number from the Exception. (in .Net 2.0)

i used

 if (exception.InnerException != null)
 {
     exception = exception.InnerException;
 }

StackTrace trace = new StackTrace(exception, true);
string fileName = trace.GetFrame(0).GetFileName();
int lineNo = trace.GetFrame(0).GetFileLineNumber();

its working fine with the exception in my application, if any exception in the reference dll i didn't get the fileName and lineNumber

هل كانت مفيدة؟

المحلول

This information is only available if the ".pdb" file for the DLL(s) in question is available.

Therefore, you should ensure that the appropriate ".pdb" files are alongside their corresponding DLLs.

You also need to enable full data in the PDB files. Debug builds do this by default, but release builds do not include the line number information.

You can configure a release build to do so by going to the project's Build page, ensure you have selected the "Release" configuration, then click the "Advanced" button at the bottom of the page. In the "Advanced Build Settings" dialog, you need to select "Full" for the "Debug Info" setting.

نصائح أخرى

The first frame is not always the right answer. In my case, it was the last one. In general, I think it is the first one with a file.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top