[Mono-list] Debug.Assert - a cross-platform issue

MarLOne InfoSeeker002 at gmail.com
Sun Mar 9 05:28:22 UTC 2014


Hi all,

I have found out the run time discrepancy of Debug.Assert() in CLR and in
Mono. The answer literally is in front of our eyes.

The difference is in this property:
System.Diagnostics.DefaultTraceListener.AssertUiEnabled.

In *CLR* the default value is *true* but in *Mono* the default value is set
to *false*. If you disassembly the system assembly, you will see that in
Mono, the DefaultTraceListener.Fail() already contains GUI code to report
the failure if the above mentioned property is true. Since the default value
is set to false, it does not report any failure condition.

Hence there are two ways of fixing it:
1) In code just do this (surround it with conditional compilation control) :
(Debug.Listeners["Default"] as DefaultTraceListener).AssertUiEnabled = true;

2) In a config file like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <system.diagnostics>
       
       <assert assertuienabled="true" />
  </system.diagnostics>

</configuration>

This setting is superfluous in CLR but is harmless hence the same config
file can be used in both platform.

If you are performing cross platform checking, make sure you include the
configuration setting to avoid the disappointment. This highlights the
importance to maintain default values consistence.

Hope this will help and may be someone maintaining this part of the code to
consider restoring that consistence.

MarL



--
View this message in context: http://mono.1490590.n4.nabble.com/Debug-Assert-a-cross-platform-issue-tp4662174p4662183.html
Sent from the Mono - General mailing list archive at Nabble.com.


More information about the Mono-list mailing list