[Mono-devel-list] Bug fix for Microsoft.VisualBasic.CompilerServices...

Christopher D. Hawkinson chawkinson at lantronix.com
Mon Apr 12 14:36:34 EDT 2004

Hi Everyone,
When trying to port some VB.NET controls to my RedHat Enterprise 3
system (Apache 2.0), I ran into a couple of issues with the
Microsoft.VisualBasic.CompilerServices class library (not surprising
considering its in its infancy). Specifically, the control uses code
such as...
            sPositionTag = Me.Style("POSITION")
            If (sPositionTag = "") Then
                sPositionTag = Me.Style("position")
            End If
If the Style option doesn't exist, Me.Style returns NULL.  The next line
which does the compare ends up calling StrCmp() within the
Microsoft.VisualBasic.CompilerServices class library. This function
causes an exception because the value being passed is a NULL object
(this code works fine on MS VB.NET, so it does appear to be legal).
Here is the new code I wrote for the StrCmp() function, so can someone
check it into the distribution source?
      public static System.Int32 StrCmp (System.String sLeft,
System.String sRight, System.Boolean TextCompare) 
                  System.Int32 leftLen;
                  System.Int32 rightLen;
                  // Set length of left and right
                  if ((object)sLeft == null) {
                        // Null, so its 0 length
                        leftLen = 0;
                  } else {
                        leftLen = sLeft.Length;
                  if ((object)sRight == null) {
                        // Null, so its 0 length
                        rightLen = 0;
                  } else {
                        rightLen = sRight.Length;
                  // Compare lengths first
                  if (leftLen == 0 && rightLen == 0) {
                        // Both are null (or zero length) so they are
                        return 0;
                  } else if (leftLen == 0) {
                        // Left is null (or zero length) so it must be
less than the right
                        return -1;
                  } else if (rightLen == 0) {
                        // Right is null (or zero length) so it must be
less than the left
                        return 1;
                  } else {
                        // Both strings have something, so compare
                        return sLeft.CompareTo(sRight);

Chris Hawkinson

This e-mail is the property of Lantronix. It is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential, or otherwise protected from disclosure. Distribution or copying of this e-mail, or the information contained herein, to anyone other than the intended recipient is prohibited.

More information about the Mono-devel-list mailing list