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

  • Home
  • SEARCH
  • 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 6567533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:20:54+00:00 2026-05-25T14:20:54+00:00

I wrote a method Assert(): [System.Diagnostics.Conditional(DEBUG)] internal static void Assert(bool condition) { if (!condition)

  • 0

I wrote a method Assert():

[System.Diagnostics.Conditional("DEBUG")]
internal static void Assert(bool condition)
{
    if (!condition)
    {
        var message =
                "Line:" + (new System.Diagnostics.StackFrame(1)).GetFileLineNumber() + "\r\n" +
                "Column:" + (new System.Diagnostics.StackFrame(1)).GetFileColumnNumber() + "\r\n" +
                "Where:" + (new System.Diagnostics.StackFrame(1)).GetMethod().Name;
            Log("ASSERTION", message);
        }
    }

Why do I have both line and column being equal to 0, when triggered? It supposed to be the place where Debug.Assert(false) is called.

Regards,

  • 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-05-25T14:20:54+00:00Added an answer on May 25, 2026 at 2:20 pm

    You need to use the StackFrame(int, bool) overload and specify true as the second argument. It looks like just the StackFrame(int) overload doesn’t capture source information.

    Sample code:

    using System.Diagnostics;
    
    ...
    
    [Conditional("DEBUG")]
    internal static void Assert(bool condition)
    {
        if (!condition)
        {
            StackFrame frame = new StackFrame(1, true);
            var message = string.Format("Line: {0}\r\nColumn: {1}\r\nWhere:{2}",
                                        frame.GetFileLineNumber(),
                                        frame.GetFileColumnNumber(),
                                        frame.GetMethod().Name);
            Log("ASSERTION", message);
        }
    }
    

    (Looking at your comments by the way, you will need the PDB files. That’s where the debug information is stored. It’s not at all clear to me whether this will work in a SQLCLR trigger, to be honest. The above works for me in a console app, but that’s all I can say…)

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

Sidebar

Related Questions

Objective-C uses a sophisticated message-passing system when one object calls a method on another
Using an idea from Bob King idea I wrote the following method. It works
I'd like to write an extension method for string, which appears as a static
Suppose someone wrote a method that opens a certain file and forgets to close
I wrote a method with an out parameter: -(NSString *)messageDecryption:(NSString *)receivedMessage outParam:(out)messageCondent { messageCondent
I wrote this method: public def getXScaleFactor(panelWidth: Int): Double = { return (panelWidth /
I wrote an extension method which returns me 2-dimensional array of YUV values from
My RenderPartial is error-ing with CS1502: The best overloaded method match for `'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has
serial.write() method in pyserial seems to only send string data. I have arrays like
I'm wanting to write a method that I can use to initialise a Map.

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.