web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics RMS (Archived)

Any way I can get the line number info from stack trace?

(0) ShareShare
ReportReport
Posted on by 165

Hello,

Writing a DLL add-in......

Process(Object ...) {

     blah..

}

In that Process method, if one of my dynamic bound object is null and being accessed, then it throws RuntimeBinderException: Cannot perform runtime binding on a null reference., obviously.

When I looked into the StackTrace info after catching that exception, unfortunately, it didn't say any line number where the exception was thrown.

I kinda could guess why it doesn't have line number info, but is there anyway somehow I can get that line number info? StackTrace/StracFrame class seems not help either...

Thanks,

*This post is locked for comments

I have the same question (0)
  • raelhefn Profile Picture
    on at

    If you need the line number for more than just the formatted stack trace you get from Exception.StackTrace, you can use the StackTrace class:

    try {

    throw new Exception();

    } catch (Exception ex)

    { // Get stack trace for the exception with source file information

    var st = new StackTrace(ex, true);

    // Get the top stack frame

    var frame = st.GetFrame(0);

    // Get the line number from the stack frame

    var line = frame.GetFileLineNumber();

    }

  • Diehard Profile Picture
    165 on at

    Have u tried this code under COM Add-in?

    Didn't I say I tried StrackTrace?

    This code wouldn't work. Since the COM Add-in runs under POS exe file context, I really can't find any reliable way to find the line number of my Add-in code from the stack trace, unfortunately.

  • raelhefn Profile Picture
    on at

    if you use this class in debugging mode it will give you line number.

  • Diehard Profile Picture
    165 on at

    Nope it won't

  • raelhefn Profile Picture
    on at

    try to trace your code using breakpoints on debugging mode.

  • Diehard Profile Picture
    165 on at

    Thanks for keep suggesting, but please re-read my question.

  • Suggested answer
    Community Member Profile Picture
    on at

    Seem to have found the solution. On VS2010 at least, with Output Debug Info set to full I also did not get line numbers within the exceptions. The trick it seems was to turn on line numbers within the editor. (Tools -> Options -> Text Editor -> All Languages -> General -> Display -> Line numbers)

  • Diehard Profile Picture
    165 on at

    Thanks for your suggestion.  I haven't tried this option, I will try tonight.

    But I don't think this will give you the line number from the exception.

    I am pretty sure this line numbers checkbox just give you the line number in the text editor in VS environment.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics RMS (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans