Archive for August 2002

 
 

Windows.Identity Doesn’t Work Under Windows 98

Here’s a .NET bug submitted by Steve Walker:

I found a bug in that when you are running a Windows Forms Application on
Windows 98, You cannot use the Windows.Identity to retrieve the user login
name, it returns a system level token and a null user name is returned when
you access the .Name Property.

To work around this I check the current windows version and make an API call
to the GetUser API instead to retrieve User Login Name.

Microsoft has confirmed to me that this is a bug and told me that it would
be fixed in the next service pack.

Steve Walker
swalker@solutionsbysteve.com

I’ve updated the .NET Bug Registry with this info.

My Submission for the Spend a Day with .NET Coding Contest

Here’s my submission for the contest that Chris Sells has organized:

The release mode executable is here.

The source is here. It’s a Visual Studio .NET solution. Simply load it with VS.NET, press F5, and it will run.

My submission is a RSS (Rich Site Summary) aggregator. RSS is a file format that encodes information about a website in an easy-to-parse XML file. Then programs like my aggregator can scan a multitude of RSS files and produce a composite web page. Perfect for those websites which you visit every day – you get one big page with everything instead of having to select them one by one from the Favorites menu. Just put your finger on the Page Down key and you can scan the new stuff super-quickly.

Why this is cool: I wrote this app because I was unhappy with existing aggregators. Radio produces nice aggregated web pages but is otherwise a pain to use. Other aggregators make you navigate all these windows and have cumbersome GUIs. Many are produced using loads of duct tape and are cumbersome to install and use. The fact that I was able to produce something that I liked better in about 12 hours of effective work just blows me away.

A part of the source code wraps the IE web browser control in a .NET object. I didn’t write that part. I got it from the Windows Forms FAQ, but had to modify it a little to make it work the way I wanted it to.

Instructions: To try the RSS Aggregator, download and the executable and save it somewhere on your hard disk. Then run it, click on the Scan Now button on the toolbar. The scanning process should start and after it’s done you should be presented with a composite web page.

To add or remove RSS feeds, go to the second tab.

Peter Drayton Comments on the Java Speed Article

I got an e-mail from Peter Drayton last weekend regarding my article on Java speed:

“In [1], you cite Andrew Appel’s paper [2] on the costs of GC vs. stack allocation and mention the need for 7x memory in order to have GC costs be < than stack allocation costs. FWIW, this is an over-simplification of the paper, which provides a means of calculating what the cross-over point is, but doesn’t claim that 7 is a universal cross-over point: it is merely the crossover point he derives using the sample inputs in the paper.

–Peter

[1] http://www.jelovic.com/articles/why_java_is_slow.htm
[2] http://www.cs.princeton.edu/%7Eappel/papers/45.ps

Thanks Peter! I have updated the article with your comments.

.NET Bugs Registry

I have started a registry of known .NET bugs. The idea is to have a place where one can check whether the weird thing he or she is seeing is a known bug, as well as a place to submit newfound bugs to. Right now it contains only things that my team or I have found, but I’m hoping that other programmers will send in their submissions.

Another Serialization Bug

My colleague Stojan reported and isolated this one. If you serialize an array of structures that implement ISerializable, they will not deserialize correctly.

Sample code:

[Serializable]
public struct TestStruct : ISerializable {

    public bool Ok;

    public TestStruct (bool ok) {
        Ok = ok;

    }

    public TestStruct (SerializationInfo info, StreamingContext context) {
        Ok = info.GetBoolean ("Ok");
    }

    public void GetObjectData (SerializationInfo info, StreamingContext context) {
        info.AddValue ("Ok", Ok);
    }

}

class TestMain {

    [STAThread]
    static void Main(string[] args) {
        TestStruct [] arr = new TestStruct [1];
        arr [0] = new TestStruct (true);

        MemoryStream stream = new MemoryStream();
        IFormatter formatter = new SoapFormatter();
        formatter.Serialize(stream, arr);

        stream.Seek (0, SeekOrigin.Begin);

        TestStruct [] readArr = (TestStruct [])formatter.Deserialize(stream);

        stream.Close ();

        if (arr [0].Ok != readArr [0].Ok) {
            Console.WriteLine ("Bug.");
        }
    }
}

This happens on the initial version of the .NET framework, with SP2 installed.

.NET ComboBox Bug

Don’t know if anyone has reported this yet, but the .NET ComboBox class has a bug that prevents the user from using the mouse to select the text in a combo box. (Initial version of the .NET framework, SP2.)

Steps to reproduce: Create a new form. Place a combo box on it. Now run the program. Enter some text into the combo. Now try selecting a part of the text using the mouse. No workie.

Cause: I didn’t dig in too deeply into the code of the combo box, but it seems that in order to fire mouse events the ComboBox class captures the mouse input of the edit box. Unfortunately, it forgets to pass those mouse messages to the edit box.

Workaround: I don’t have one. I could listen to mouse events and then send the edit box messages when they happen, but that would probably break when Microsoft fixes this bug. The best bet seems to be writing a new combo box wrapper, but I still haven’t gotten around to doing that.

.NET Serialization Bug

Here’s a .NET serialization bug that affects both the SoapFormatter and BinaryFormatter:

If you have three or more classes that:

  1. Are part of the same inheritance hierarchy
  2. Have the same name but are in different namespaces
  3. Have a variable that is named the same

Then these objects will not be serialized properly and deserialization will either fail silently or throw an exception.

Example:

Try serializing the class T3.TestClass below using the SoapFormatter:

namespace T1 {
    [Serializable]
    public class TestClass {
        private string myValue = "test";
    }
}

namespace T2 {
    [Serializable]
    public class TestClass : T1.TestClass {
        private int myValue = 2;
    }
}

namespace T3 {
    [Serializable]
    public class TestClass : T2.TestClass {
        private int myValue = 3;
    }
}

What you will get as output is:

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<a1:TestClass id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/FutureSource.UndoTestProject.T3/UndoTestProject%2C%20Version%3D1.0.965.20674%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<myValue>3</myValue>
<TestClass_x002B_myValue>2</TestClass_x002B_myValue>
<TestClass_x002B_myValue id="ref-3">test</TestClass_x002B_myValue>
</a1:TestClass>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Notice the two red lines? The variables myValue from classes T1.TestClass and T2.TestClass are improperly mapped to the same name TestClass_x002B_myValue. When the formatter later tries to deserialize this it will wrongly try to assign both the string and the integer to T2.myVaue and fail.

Cause: When three classes that are part of the same hierarchy have a variable that has the same name, the two .NET formatters will keep one name intact when serializing and encode the other two as class name+variable name. Unfortunately, it does not use the full class name (e.g. namespace + class name) when encoding but only the short class name.

Workaround: Write your own serialization surrogate that encodes variable names as variable name+height of declaring class in the hierarchy.

Windows Forms Bug

Here’s an interesting bug that causes a Windows Form to enter a state where it cannot be closed. I’m using the initial version of the .NET framework with SP1 installed.

Steps to reproduce: Create a new form, A. Put a user control B onto it. Put another user control, C, onto the control B. Finally, put a button onto C. At this point you should have something like this:

Form A, user controls B and C, and a button.

Write an event handle for the button click that causes the user control C to be removed from its parent, B.

Now, run the app and click on the button. You should end up with a form that looks like the one below. Now try to close the form by clicking on the close button – doesn’t work, right?

Form A cannot be closed now.

Cause: The form is refusing to close because its Close method is trying to validate the control first, and validation fails because its unvalidatedControl private member still points to the button which has been removed from the hierarchy.

Workaround: After removing the user control C, call a.OnControlRemoved (c) in order to clear the unvalidatedControl variable.

Code: If you want to try this yourself a demo project can be found here.