473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Debug.Assert() message so large it is cropped

I am getting a Debug.Assert() firing which shows a mesasge so large
that it is cropped. But it crops off the beginning. So, I have no
idea what assertion is.

My code is not complex. It's just the main form invoking the c'tor of
a class, and this c'tor calls a static function that fires the
assertion. So, it's just Form1 -Class C'tor -Membe Function.

What can I do about this? Is Debug.Assert() really this useless?
There has to be a work around. I can't see this being a problem that
no one noticed. But, I also can't see this not being easily
reproducable on any workstation. Can I increase the message size?

thank for any help!!

Zytan

Feb 25 '07 #1
8 2012
So, I have no idea what assertion is.
...
Is Debug.Assert() really this useless?
This isn't true since, duh, if I clicked 'Retry'=Debug, I go straight
to the source code of the assertion!

But, I'd still like to know why the entire message doesn't show.

Zytan

Feb 25 '07 #2
"Zytan" <zy**********@yahoo.comschreef in bericht
news:11**********************@t69g2000cwt.googlegr oups.com...
>So, I have no idea what assertion is.
...
Is Debug.Assert() really this useless?

This isn't true since, duh, if I clicked 'Retry'=Debug, I go straight
to the source code of the assertion!

But, I'd still like to know why the entire message doesn't show.

Zytan
You can see the entire message in the output window too (VS - Ctrl+W, O).

Reagrds,
Anne
Mar 1 '07 #3
You can see the entire message in the output window too (VS - Ctrl+W, O).

Yes and no. You can see the *same truncated* message in the Output
Window. You cannot see the entire message in the OutPut Window.

No, WAIT A SECOND, I'm wrong. I see this in the Output Window:

---- Assert Short Message ----

---- Assert Long Message ----
at LoginForm.btnTest_Click(Object sender, EventArgs e) C:\path\to
\the\source\file.cs(line_number)
....
....
etc.

Which is the same as in the message box. Is this how the assertion is
displayed? Where's the TEXT of the assertion from the code itself???

Oh right, c# has no macros, so the can't implement _assert like C
does. Damn.

I wish the message box didn't leave 3 or 4 empty lines implying that
there's something missing, and start the assertion with "at" implying
there's something missing.

Ok, this is something the compiler could do. It already removed all
Debug. calls, so why not add even more code to the Debug.Assert, and
pass in the TEXT of the assertion, so we know what the problem is?

Zytan

Mar 1 '07 #4
Oh right, c# has no macros, so the can't implement _assert like C
does. Damn.
Instead of using the DefaultTraceListener you can write your own Listener
class (derived from TraceListener) to output the message to a file, eventlog
(e-mail, WWW, RSS, SMS or whatever way you want to get notified).

To give a clue, here is a basic sample using the StackTrace class (has to be
improved):

public class MyListener : TraceListener
{
public override void Write(string message){} // work this out
public override void WriteLine(string message){} // work this out

public override void Fail(string message)
{
HandleFail(message, string.Empty);
}

public override void Fail(string message, string detailMessage)
{
HandleFail(message, detailMessage);
}

private void HandleFail(string message, string detailMessage)
{
StackTrace st = new StackTrace(true);
Console.WriteLine("{0} {1}\r\n{2}", message, detailMessage, new
StackTrace(true).ToString());

}
}

public static void Main()
{
Trace.Listeners.Add(new MyListener());
Debug.Assert(false, "Oops"); // force assertion
Trace.Flush();
}

Regards,
Anne
Mar 1 '07 #5
Instead of using the DefaultTraceListener you can write your own Listener
class (derived from TraceListener) to output the message to a file, eventlog
(e-mail, WWW, RSS, SMS or whatever way you want to get notified).

To give a clue, here is a basic sample using the StackTrace class (has to be
improved):
Wow, cool! I don't need anything like this for now, but thanks, Anne!

Zytan

Mar 1 '07 #6
Instead of using the DefaultTraceListener you can write your own Listener
class (derived from TraceListener) to output the message to a file, eventlog
(e-mail, WWW, RSS, SMS or whatever way you want to get notified).
I better understand what you were saying now, from our most recent
thread. Although to be critical, I wouldn't need my own TraceListener
class to log to a file, as this article you gave me shows:
http://www.15seconds.com/issue/020910.htm

I am not sure why. Oh, because a TextWriterTraceListener already
exists (the class I would have made). But, yes, for something else,
other than writing to a file, I'd need to make my own.
To give a clue, here is a basic sample using the StackTrace class (has to be
improved):

public class MyListener : TraceListener
{
public override void Write(string message){} // work this out
public override void WriteLine(string message){} // work this out

public override void Fail(string message)
{
HandleFail(message, string.Empty);
}

public override void Fail(string message, string detailMessage)
{
HandleFail(message, detailMessage);
}

private void HandleFail(string message, string detailMessage)
{
StackTrace st = new StackTrace(true);
Console.WriteLine("{0} {1}\r\n{2}", message, detailMessage, new
StackTrace(true).ToString());

}

}

public static void Main()
{
Trace.Listeners.Add(new MyListener());
Debug.Assert(false, "Oops"); // force assertion
Trace.Flush();
}

Regards,
Anne
Thanks Anne, this is a great help!

Zytan

Mar 2 '07 #7
thread. Although to be critical, I wouldn't need my own TraceListener
class to log to a file, as this article you gave me shows:
http://www.15seconds.com/issue/020910.htm

I am not sure why. Oh, because a TextWriterTraceListener already
exists (the class I would have made). But, yes, for something else,
other than writing to a file, I'd need to make my own.
TextWriterTraceListener writes only the string parameter(s) of Debug.Assert.
You wanted the entire stackdump, so I suggested to create your own
TraceListener.

Regards,
Anne
Mar 2 '07 #8
TextWriterTraceListener writes only the string parameter(s) of Debug.Assert.
You wanted the entire stackdump, so I suggested to create your own
TraceListener.
Oh, right, that is very cool. I don't think the Debug.Assert messages
were being cropped, so it's ok. But, that's a neat feature to be able
to show the call stack.

Thanks, Anne

Zytan

Mar 3 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Alexander Malkis | last post by:
Why do programmers like to use NDEBUG instead of DEBUG? -- Best regards, Alex. PS. To email me, remove "loeschedies" from the email address given.
27
by: Daniel Vallstrom | last post by:
I'm having problems with inconsistent floating point behavior resulting in e.g. assert( x > 0.0 && putchar('\n') && x == 0.0 ); holding. (Actually, my problem is the dual one where I get...
4
by: emma middlebrook | last post by:
I have a question regarding asserting ... here's some code: string GetAssertMessage() { ... prepare a message string and return it... } void SomeMethod() { ...
2
by: cody | last post by:
System.Diagnostics.Debug.Assert(); Hello??? A language should encourage programmers to heavily use the assert-feature, since it improves safety, stability, readability and maintainability of...
1
by: High and dRy | last post by:
Hello, I created a simple .NET C++ console application. And the Debug::Assert(false) statement is popping a message box in release version also. Any idea why ? Any complier settings I need to do...
7
by: Srinivasa Rao | last post by:
I have read in one article that when we compile the application in release mode, all the debug classes and properties will be automatically removed from the code. I tried to implement this thing by...
5
by: Mr Newbie | last post by:
Debug.Assert( False, "Why wont I display ??") I am trying to use this in my code but it wont display. The app is running on my local machine and the above code under a button click event. What...
3
by: Brian Cryer | last post by:
It would be very handy to be able to stop the debugger on parts of code without having to explicitly set a breakpoint - either a "debugger.break" or "debug.assert" type of thing would do. I've not...
2
by: joelkeepup | last post by:
Hi, I made a change this morning and now im getting an error that says either "a is undefined or null" or "e is undefined or null" the microsoft ajax line is below, I have no idea how to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.