[Mono-dev] Inconsistent value in System.Diagnostics.DefaultTraceListener.AssertUiEnabled

MarLOne InfoSeeker002 at gmail.com
Fri Mar 14 12:42:30 UTC 2014


Hi,

I am running "Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-5ubuntu1)"
in Mint-15 Cinnamon (64-bits) and also in Ubuntu 12.04 LTS (32-bits). My
development is using MonoDevelop 4.2.2 and obtained from PPA
(https://launchpad.net/~ermshiperete/+archive/monodevelop)

The problem is frequently reported in the Mono-forum complaining
Debug.Assert( false ) never stop and and warn user when the assertion fails.

The function System.Diagnostics.Debug.Assert(bool, string) is not at fault
as I have disassembled the Mono code. The fault lies in the property value
of *System.Diagnostics.DefaultTraceListener.AssertUiEnabled* which is
default to *false* in *Mono* while in *CLR's runtime code* it is default to
*true*.

Here is the way to check cross-platform consistency:
1) Create a console application Windows/CLR containing the following code
#if DEBUG
if( (System.Diagnostics.Debug.Listeners["Default"] as
DefaultTraceListener).AssertUiEnabled == false )
  throw new Exception( "Wrong Default Value" );
#endif

Do not use NUnit to perform this test as NUnit automatically setting this
value to false so that user's Debug.Assert() does not interfere with the
NUnit.Framework.Assert class' operations. By default, it is written to
console in NUnit.

Attached is the MonoDevelop project called VerifyAssertUiEnabled.zip
VerifyAssertUiEnabled.zip
<http://mono.1490590.n4.nabble.com/file/n4662230/VerifyAssertUiEnabled.zip>  

2) Run the console application in Windows and you should see *NO* exception.

3) Take the console application to Linux with Mono runtime installed and run
it, you will see the Exception telling the property value is different.

You can restore the consistency between CLR and Mono so that
Debug.Assert(false) will not be silenced  in Mono in the following way:
1) In Code
#if DEBUG
DefaultTraceListener defListener = Debug.Listeners["Default"] as
DefaultTraceListener;
if( defListener != null )
{
   // available
   defListener.AssertUiEnabled = true;
}
#endif

2) Using a configuration file with the following contents (this is harmless
in CLR)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.diagnostics>
       
       <assert assertuienabled="true" />
  </system.diagnostics>
</configuration>

Clearly the default value in DefaultTraceListener.AssertUiEnabled is
producing inconsistent run time behaviour between CLR and Mono. Perhaps it
is due to the fact the developer has forgotten to initialise the
DefaultTraceListener.AssertUiEnabled value.

MarL




--
View this message in context: http://mono.1490590.n4.nabble.com/Inconsistent-value-in-System-Diagnostics-DefaultTraceListener-AssertUiEnabled-tp4662230.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list