The .NET Framework revisited

This article was originally published in VSJ, which is now part of Developer Fusion.
The beauty of .NET is that most of the facilities are provided by the .NET Framework, and so are common to all of the .NET languages. Learning your way around the class library is something that takes time, and a common occurrence is to discover only after you have implemented your own solution that a suitable class did exist but not quite where you expected it.

With .NET 2.0 the lesson is to keep looking longer and harder because the chances have increased that there will be a class ideal for the job. The additions are far too numerous to catalogue in their entirety; what I can do is to select a few that I think are particularly inspiring in the sense that they make it easy to do something that was difficult. I’m not going to mention generics and generic collections because these important improvements have been discussed in connection with C# 2.0 and VB 2005, nor improvements in the ASP.NET classes.

First it is worth saying that there have been efficiency improvements in a great many areas – shorter start-up time, smaller working set, faster Interface and delegate invocation and so on. The Framework also now offers 64-bit compatibility with the flick of a compiler switch. A 64-bit application can access more than 4Gb of memory, but it can’t access 32-bit components.

An interesting change is manifest-based activation. Instead of being activated by a reference to an assembly, the manifest is used. The advantage is that the manifest contains a full description of the application including security requirements, and this makes “ClickOnce” applications possible. The user is given the option of reviewing the security requirements before downloading the code. New classes and additions to existing classes are provided to support manifest-activation.

One area of improvement that will have an impact on most programmers is COM interop and Pinvoke. It would be nice not to need it, but in practice we still do. Calls between applications in different application domains have been speeded up. The new SafeHandle and CriticalHandle classes are available to wrap system handles safely. Marshalling has been improved to allow native function pointers to be wrapped by a delegate, and can now handle fixed-size arrays of structures within structures.

As you would expect, there are lots of new network-oriented classes. The NetworkChange class detects when any change to the network configuration occurs – disconnected cable, lost wifi signal etc. – and notifies the application. The NetworkInfomation namespace contains classes that can retrieve network traffic statistics. There’s direct support for FTP, and the HttpListener class allows you to create a web server within an application. The Cache class gives you control over the caching of resources obtained by WebRequest, WebResponse and WebClient. You can use predefined policies or create your own. Last, and in many ways least, is the new Ping class…

A console may be an old-fashioned thing, but if you are going to have one you might as well have a good one. The new Consol class has moved beyond the simple text window and has methods that allow you to move an area of the screen buffer so that you can create smooth animation. It also has new methods for keyboard I/O and control of colours used, cursors and the consol beep. It’s good enough to be usable to implement some classic games!

Security is an area where application programmers have to pay more attention, and there are easy-to-use cryptographic classes. The Negotiate Stream and SslStream classes let you authenticate and transmit encrypted data using standard protocols. The Data Protection API (DPAPI) includes methods that allow you to encrypt passwords, keys and connection strings, all within the managed environment. It can even be used to encrypt blocks of memory. At a slightly higher level, certificate management has been improved, and you can now work with the X.508 certificate infrastructure. This allows you to sign and verify XML using a certificate. You can also use PKCS7 signature and encryption, making it easier to work with S/MIME. This combination makes it virtually unnecessary to resort to P/Invoke and the Crypto API. A slightly different slant on security is provided by the new Access Control List (ACL) classes. Many programmers avoid any contact with ideas such as the ACL because it is something to do with systems administration; however, the new classes allow you to create and manage an ACL so controlling access to a resource.

As well as classes to work with secure streams, the basic I/O classes now do more and are easier to use. In particular you can now read and write GZIP compressed data directly from disk.

The one thing you can say about class libraries is that they keep on growing. The .NET framework is developing in a way that is logical and manageable. What is always surprising is that there is still room for additional classes. It is clear that in the future the Framework will probably have to be split into sub-libraries dealing with different areas.


Dr Mike James, editor of VSJ, has over 20 years of programming experience, both as a developer and lecturer. He has written numerous books and articles on programming, and his PhD is in computer science.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The difference between theory and practice is smaller in theory than in practice.”