Was it just me, or was Microsoft’s release of the second public beta edition of the .NET Framework done with little fanfare? The problem with such a quiet release is that only people who are paying rapt attention notice. The rest of the world remains blissfully ignorant, and as a developer, I’m not sure that .NET is something you want to remain totally ignorant about for long. So in this article, we’ll take a look at some of the new wrinkles in the latest edition of Microsoft’s new platform. First, let’s look at language changes.
VB.NET
Visual Basic.NET received many changes, most of which were aimed at keeping compatibility with certain language features and syntax of “classic” VB. The two biggest of these changes were:
- The integer equivalent of Boolean True is now –1, as it was in VB6.
- For array declarations, the number specified when creating a new array will define the upper bound of the array instead of the number of elements in the array. For example, specifying 10 would result in an array with 11 elements, 0 to 10. This also brings .NET’s array behavior in line with VB6.
These changes didn’t really surprise me, as they were largely concessions to a faction of current VB programmers’ loud complaints about VB.NET’s new syntax. A little more surprising to me was the reinstatement of VB6’s overloaded And, Or, Xor, and Not bitwise and Boolean operators. And none of these operators perform short-circuit evaluation any longer. Instead, Microsoft introduced new keywords to support short-circuiting: AndAlso and OrElse.
Other less radical changes included:
- Classes found in the Microsoft.VisualBasic.Compatibility.VB6 namespace were moved to Microsoft.VisualBasic.
- Attributes for most code elements should be placed before the declaration of the element, instead of immediately before the identifier. This should make attributed code much more readable.
- XML WebForm attributes are now case sensitive.
- VB.NET’s persistence format changed in such a way that existing WebForms created for Beta 1 will not open unless they are manually updated to use the new persistence format.
Get your beta here
If you haven’t had a chance to play around with the .NET Framework SDK yet, or if you’ve seen Beta 1 and would like to see something a bit closer to the finished product, be sure to download Beta 2 from Microsoft.
C#
The new C# language received numerous changes to bring it more in line with its language specification and documentation. Numerous holes were closed in the compiler’s enforcement of language rules, like assignable foreach loop control variables and the nonenforcement of the requirement that the last clause of a switch statement end with a break, return, or something similar.
C#’s attribute mechanism also got some tweaks. Attributes can now specify a target argument to explicitly specify which code element they belong to. Doing so removes some of the ambiguity in C#’s scheme of assuming that an attribute belongs to the code element it’s closest to. In addition, all attributes must now translate to actual attribute classes in C#’s base class libraries, and some attributes, such as commethod and nativetype, are no longer supported.
Some other changes included:
- Overridden methods can also be sealed by using the sealed modifier to prevent child classes from overriding the method themselves.
- Virtual members of a base class can be overridden by abstract members of a child class.
- XML comments support an <include> statement that allows documentation to be retrieved from another XML file.
- The compiler will generate a NullReferenceException if code attempts to call a nonvirtual method on a variable having the value of null. Previously, an exception was thrown only if the method attempted to dereference this.
- The using keyword now works correctly, although I for one didn’t know it was broken.
Managed C++
Many of the changes in C++.NET dealt with implicit management of certain classes. Classes that inherit from a garbage collector class and enums defined in a managed class are both no longer implicitly managed by the Common Language Runtime.
The __gc and __nogc adornments of the new keyword that can be used to create objects on the managed or unmanaged heaps now work as they were intended. The compiler also creates destructors for all managed classes and names them Finalize. This means that programmers cannot implement Finalize methods in managed classes. Since this method is a protected member of the System.Object base class, this also means that the Finalize method of an object can’t be directly called from a pointer to an object’s base class.
Other changes
Given the .NET class library’s maturity level, changes to its classes and namespaces are to be expected. More than 80 pages of the 108-page change document deals with changes to the .NET class libraries. So there are simply too many changes to talk about here. Instead, I’ll just focus on a few that jumped out at me while I browsed the change list:
- A big change involves the regular expression parser, Regex. Regex now expects options arguments to be of the enum System.Text.RegularExpressions.RegexOptions type instead of strings, as in Beta 1. Multiple options can be bitwise Or-ed together.
- Two collection classes, CaseInsensitiveHashtable and CaseInsensitiveSortedList, were removed from the Systems.Collections namespace and replaced with a single class, System.Collections.Specialized.CollectionsUtil. These were apparently just specialized forms of other collections, so this change shouldn’t really be a big deal.
- The file system classes have been refactored into multiple classes that better reflect the Windows file system’s hierarchy. Also, the System.Currency class has been removed. Microsoft suggests replacing it with System.Decimal instead.
According to Microsoft’s late-breaking issues pages, ADO.NET is still unable to connect to ODBC data sources. So if you want to access ODBC data with ADO.NET, you’ll need to download the beta copy of the ODBC.NET provider from Microsoft—which I’m sure brings its own set of problems. Microsoft also stresses that ADO Recordsets opened using the COM interoperability classes should be explicitly closed. Otherwise, you run the risk of an access violation and crash.
Finally, whole class library namespaces appear to no longer work correctly on Windows NT, XP Home, Me, and 9x. These namespaces include elements of System.Web, System.ServerProcess, and System.Diagnostics—which essentially means that ASP.NET now functions only on Windows 2000. Depending on your situation, this fact could be anything from a nonissue to a large annoyance.