Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7932217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:56:57+00:00 2026-06-03T20:56:57+00:00

I am writing my own poor-man’s testing framework. In my console application, I have

  • 0

I am writing my own poor-man’s testing framework. In my console application, I have this:

  static void Main(string[] args)
  {     // Line 12
     double adouble = 77;
     double expected = 70;
     TestingFramework.assertEquals<double>(expected, adouble - 7);  // Line 15
     TestingFramework.assertEquals<double>(expected, adouble - 6);  // Line 16
   }

Within TestingFramework I have this line:

System.Console.WriteLine("Success, File {0}, Line {1}", 
   new System.Diagnostics.StackTrace(true).GetFrame(1).GetFileName(), 
   new System.Diagnostics.StackTrace(true).GetFrame(1).GetFileLineNumber());

But when I run the test, it tells me that FileLineNumber is 12 for both function calls. Further, it gives me the correct file name, so I am think it is referencing the correct frame.

Can someone tell me how I can get it to report to me the line number that originated the call (15 then 16), and not the line number of the open paren (12)?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:56:59+00:00Added an answer on June 3, 2026 at 8:56 pm

    I have figured out the problem and how to fix it.

    I had overloaded the assertequals function in TestingFramework:
    1) assertEquals(T expectedValue, T actualValue) and
    2) assertEquals(T expectedValue, T actualValue, string comment).

    When client code calls the 2-param function, that function just calls the 3-param function. This different frame depths depending on how it was called.

    So I had to add

    static int depth; 
    

    which I increment when entering a function and decrement when exiting. This changes the code to:

    new System.Diagnostics.StackTrace(true).GetFrame(depth).GetFileLineNumber()); 
    

    and that now works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing my own HtmlHelper extenstion for ASP.NET MVC: public static string CreateDialogLink
I am writing my own 'Rubik's cube' application. The main class Cube has 18
I am writing my own blog (every one should, it's good experience). I have
I'm writing my own CSS for jQuery UI. Basically, I need to have different
I have started writing my own WebDAV server class in .NET, and the first
I'm writing my own shell, and seem to have some kind of problem with
I am writing my own custom configuration section and have a ConfigurationProperty defined in
I'm writing my own PriorityQueue class and I have: private Queue<E>[] queues; public PriorityQueue(int
I am writing my own Graph library Graph++ , I have question regarding what
When writing my own events to the error log, do I have to have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.