What's New in the BCL in .NET 4.0 CTP [Justin Van Patten]
The Visual Studio 2010 and .NET Framework 4.0 CTP is available for download as of last week. The CTP contains new functionality throughout the .NET Framework, including several new BCL features and improvements:
Code Contracts
System.Diagnostics.Contracts provides a language-agnostic way to express coding assumptions in .NET programs. The contracts take the form of pre-conditions, post-conditions, and object invariants. Contracts act as checked documentation of your external and internal APIs. The contracts are used to improve testing via runtime checking, enable static contract verification, and documentation generation. We partnered with Microsoft Research to deliver this feature in .NET 4.0. More information and tools are available on Microsoft Research’s code contracts website. There’s also a highly-rated PDC session available online.Parallel Extensions
We worked with the Parallel Extensions team to add the Task Parallel Library (TPL), Coordination Data Structures, and Parallel LINQ (PLINQ) to the BCL in .NET 4.0. This includes an improved ThreadPool scheduling algorithm for tasks, the static Parallel class, concurrent collections in System.Collections.Concurrent, and other coordination data structures such as LazyInit<T>, CountdownEvent, Barrier, SemaphoreSlim, SpinLock, SpinWait, and ManualResetEventSlim. More information is available over at the PFX team’s blog. Also, check out Daniel Moth’s PDC session on Parallel Programming for Managed Developers with the Next Version of Microsoft Visual Studio.BigInteger
System.Numerics.BigInteger is an arbitrary-precision integer data type. We worked with the Microsoft Solver Foundation team to deliver a highly performant big integer implementation. BigInteger supports all the standard integer operations, including bit manipulation. It can be used from any .NET language, and some of the new .NET languages—such as F# and IronPython—have support built-in to the language.Memory Mapped Files
System.IO.MemoryMappedFiles exposes the memory mapping functionality provided by Windows as first-class managed APIs. Memory mapped files can be used to efficiently edit very large files and can also be used to create shared memory for inter-process communication. Along with this feature, we’re also introducing System.IO.UnmanagedMemoryAccessor, a new class that enables random access to unmanaged memory similar to how UnmanagedMemoryStream enables sequential access to such memory.ResourceManager Improvements
The ResourceManager in System.Resources has been improved to respect the user’s preferred UI languages when looking for localized resources, instead of only using the CurrentUICulture’s parent chain. This means if the user has specified that she prefers French and Spanish, the ResourceManager will look for French and Spanish resources before falling back to the neutral resources. This change is present in Silverlight 2 as well as .NET 4.0.Compression Improvements
The compression algorithms in System.IO.Compression have been improved in .NET 4.0. DeflateStream and GZipStream no longer inflate already compressed data. This means that in most cases you’ll see much better compression ratios when using these streams on .NET 4.0. We’ve also removed the 4 GB size limit, so you can now compress streams over 4 GB in size.String Security Changes
The default partial matching overloads on System.String (StartsWith, EndsWith, IndexOf, and LastIndexOf) have been changed to be culture-agnostic (ordinal) by default. In addition, ToUpper and ToLower on System.String and System.Char have been changed to use the invariant culture instead of the current culture. Although we haveguidanceandFxCop rulesthat recommend always using overloads that take a StringComparison parameter, unaware developers often just use the default overloads. In previous versions of .NET, these default overloads do a culture-sensitive comparison using the current culture. This can often lead to subtle bugs, most notably security vulnerabilities, when unaware developers use the default overloads to do security-sensitive string comparisons. This change helps mitigate these vulnerabilities. The change is present in both Silverlight 2 and .NET 4.0. Even with these changes, our guidance still stands: whenever an overload exists that takes a StringComparison parameter, use it instead of an overload that does not take this parameter. It makes your code clearer and easier to maintain. This is especially important because the default overloads for String.Compare and String.CompareTo will remain culture-sensitive because these methods are most often used when sorting strings to be shown to the user. We plan to add a compat switch in the beta that will allow an app to specify whether it wants the old behavior.UPDATE for .NET 4 Beta 1 In order to maintain high compatibility between .NET 4 and previous releases, we have decided to revert this change. The behavior of String's default partial matching overloads and String and Char's ToUpper and ToLower methods now behave the same as they did in .NET 2.0/3.0/3.5. The change back to the original behavior is present in .NET 4 Beta 1. We apologize for any interim confusion this may cause. We continue to recommend being explicit about the string comparison behavior you want, by always specifying a StringComparison value for the methods on String that accept it.
We’re also evaluating a number of potential new features and improvements for .NET 4.0 beta:
Variance annotations
The next versions of C# and VB support safe co- and contra-variance for generic interface and delegate types. Co-variance means that a generic of a type, e.g. an IEnumerable<String>, can be treated as a generic of any supertype, e.g. an IEnumerable<Object>. Contra-variance means that a generic of a type, e.g. an Action<Object>, can be treated as a generic of a subtype, e.g. an Action<String>. In C#, co-variance is annotated with the “out” keyword and contra-variance is annotated with the “in” keyword. We are annotating several interfaces and delegates in the BCL for variance. You can learn more about co- and contra-variance in Anders Hejlsberg’s PDC session on The Future of C#.Tuples
We are providing common tuple types in the BCL to facilitate language interoperability and to reduce duplication in the framework. A tuple is a simple generic data structure that holds an ordered set of items of heterogeneous types. Tuples are supported natively in languages such as F# and IronPython, but are also easy to use from any .NET language such as C# and VB.SortedSet<T>
We plan to add a SortedSet<T> collection along with an ISet<T> interface. SortedSet<T> uses a self-balancing tree which maintains data in sorted order for performance guarantees with insertion, deletion, and searches. Both the new SortedSet<T> and the existing HashSet<T> implement ISet<T>.File System Enumeration Improvements
We plan to add new file system enumeration APIs to System.IO.Directory and System.IO.DirectoryInfo that return IEnumerable<T>’s instead of arrays. These new APIs are more efficient than the array-based APIs because they do not need to allocate a (potentially large) array and you can access the first results immediately instead of waiting for the entire enumeration to take place. We’re also planning to add new convenience APIs for efficiently reading, writing, and appending lines from/to a text file using IEnumerable<String>. These new APIs are useful in LINQ scenarios where you may want to quickly and efficiently query the contents of a text file and write out the results to a log file without allocating any arrays.
There are also a bunch of improvements to the CLR in .NET 4.0. Here’s a high-level summary:
- In Process Side-by-Side: support for multiple CLR versions running in the same process.
- Interop improvements: no PIAs (check out Under the Hood: Advances in the .NET Type System and Managed and Native Code Interoperability: Best Practices)
- Simplified security model
- GC improvements (notifications and low-latency background collections)
- Profiling improvements (ability to attach/detach performance and memory profilers on the server)
- Debugging enhancements (support for Windows Error Reporting mini-dumps)
You can learn more about the next version of the CLR in Joshua Goodman’s PDC session on Microsoft .NET Framework: CLR Futures.
Over the next couple of weeks we’ll be posting more about the new functionality that’s available in the CTP. Do note that we’re working on many other improvements for 4.0 that we’re not quite ready to announce just yet.
As always, we’d love to hear what you think of the CTP and announcements so far.
Comments
Anonymous
November 04, 2008
PingBack from http://mstechnews.info/2008/11/whats-new-in-the-bcl-in-net-40-justin-van-patten-2/Anonymous
November 04, 2008
Ah, the BigInteger makes its return. Heheh. Let's hope it sticks this time around!Anonymous
November 04, 2008
So, I've looked at the research implementation of Code Contracts for VS2008, are there any differences between the VS2008 research version of Code Contracts and the RTM .NET 4.0 version. I think the functionalities in the Code Contract framework are cool, but using the framework as well as the integration in VS2008 feels kinda sketchy.Anonymous
November 04, 2008
Contracts are wonderful! I only wish they were properly integrated into the languages (C# and VB); well, now that they're there, I would expect that there will be work towards that in C# 5.0 & VB11. Aside from the less clumsy syntax, it would also easily enable proper contract inheritance. Why such restrictive license for the present Managed Contracts for VS2008 release, though? BigInteger - expected since 3.5; 'nuff said. Changes in System.String - I'm sure that Michael Kaplan will be jubilant ;) Tuples - yes, please! Bonus points if you make them F#-compatible (i.e., so that F# tuples would use the corresponding BCL class under the hood, or at least be implicitly convertible to/from it). I guess that would require cooperation with the F# team, but I think it's well worth it.Anonymous
November 04, 2008
I agree, this move towards putting everything in the framework instead in the language, even when extending the langauge makes much more sense, is concerning. I know why they do it: eiether it's easier to create a runtime for the features; or it much easier adds the capability to other languages (the goal of .NET); perhaps makes it easier to extend and enhance, even. But still, things like contracts and parallelism and so on just feel much better in the langauge. Hopefully a future JIT will do some uber optimizations on such things so it isan't all function calls, virtual calls, and lambda calls overhead. Regardless, I've long wanted a contracts feature and have created my own (get this: framework for it too) but it's nice now to have it as part of the commons. Thanks, ShawnAnonymous
November 04, 2008
I wish that all BCL methods taking arrays were reviewed. Top of my list is String.Join(). It's stupid to deal with List<T> and IEnumerable<T> and then have to .ToArray() on them just to perform the common operation of joining sequences with a delimiter.Anonymous
November 04, 2008
You're right that the StringComparison enum should always be used where there is an overload that supports it. So why is it that String.Replace(String,String) still doesn't take a StringComparison arg? The String.Contains method is another oversight. I logged a case on Ladybug years ago for these two methods to gain a StringComparison. Years! If you would fix these two methods in .NET 4.0, that would make me VERY happy. P.S. Your changes to existing String methods to be ordinal/invariant instead of culturally aware is welcome, long overdue, and the way it should have been done in the first place. However, I think we all know the dangers of people recompiling their .NET 1/2/3 code against .NET 4.0 and suddenly getting the different behaviour. Much migration guidance needs to be given.Anonymous
November 04, 2008
I've been reading with interest about the SSE support in Mono... any chance similar changes could appear in MS's CLR?Anonymous
November 04, 2008
Thanks a great time at the PDC 2008 - I enjoyed the talk with Kim Hamilton at the BCL session (ask the experts). I second the request for reviewing all methods that take arrays and determine whether IEnumerable<T> should be introduced also. Regarding the string class, I'd like to request that string.Contains is overloaded to take params (i.e. "contains all these strings" instead of just one operator). Also string.ContainsAny with params would be nice as it's a very common pattern among developers to check a string for either N or any inclusive instances of other strings. The SortedSet<T> is definately a keeper.Anonymous
November 05, 2008
Come molti di voi sanno, da qualche giorno è possibile scaricare dal sito Microsoft una macchina virtualeAnonymous
November 05, 2008
I’m not pleased where this whole co- and contra-variance thing is going. Don't get me wrong, this is what we all want, but I don't want language support; I want CLR support! In C# 4.0 it's currently implemented as a bad language trick. It only works on interfaces and delegates. Since you are releasing a new version of the CLR with the next version of the framework (and don't get me started on the CLR’s new version number), you have change to make a real change here and don't leave it up to the language teams. Are you working on platform support for this for all generic types?Anonymous
November 05, 2008
We are working with F# to make sure the Tuple is compatible. In fact, great deal of effort went into this already, more than what meets the eye here :-Anonymous
November 05, 2008
Hi Johannes, >>>>> are there any differences between the VS2008 research version of Code Contracts and the RTM .NET 4.0 version The Microsoft Research implementation and .NET implementation are very much in sync. However, there will likely be a few differences by the time we ship. It should be relatively easy to switch once we have these in production and not just up as a research project for non-commercial use. Thanks, JustinAnonymous
November 05, 2008
Hi int19h, >>>>> I only wish they were properly integrated into the languages (C# and VB) We won’t have language support for contracts in .NET 4.0, but this is something we will consider for releases down the road. In the meantime, the APIs can be used from any language. >>>>> Why such restrictive license for the present Managed Contracts for VS2008 release, though? This is mainly due to the fact that this feature is in active development and that Microsoft Research is not set up to support/service the research project if there are any bugs/issues with it. But we are productizing this for 4.0, meaning in 4.0 / VS 2010, this will be fully supported. >>>>> I guess that would require cooperation with the F# team, but I think it's well worth it. As Ravi mentioned, we have been working with the F# team on compatibility :-) Thanks, JustinAnonymous
November 05, 2008
Hi RichB, >>>>> I wish that all BCL methods taking arrays were reviewed. Top of my list is String.Join(). It's stupid to deal with List<T> and IEnumerable<T> and then have to .ToArray() on them just to perform the common operation of joining sequences with a delimiter. Thanks for the suggestion. We’ll see if we can address some of these pain points in 4.0. Thanks, JustinAnonymous
November 05, 2008
Hi Andrew, >>>>> So why is it that String.Replace(String,String) still doesn't take a StringComparison arg? The String.Contains method is another oversight. This indeed has been a longstanding oversight that we’ve been meaning to address for quite some time. Unfortunately the nature of our 3.0 and 3.5 releases (layer cake model) means we haven’t been able to address some of these oversights since we released 2.0. The good news is that we’re planning to finally address this in 4.0 :-) >>>>> However, I think we all know the dangers of people recompiling their .NET 1/2/3 code against .NET 4.0 and suddenly getting the different behaviour. Much migration guidance needs to be given. We are very mindful of this. In addition to guidance, we’ll also provide an app compat switch that will allow older apps to specify that they want the old behavior. Thanks, JustinAnonymous
November 05, 2008
Hi Stu, >>>>> I've been reading with interest about the SSE support in Mono... any chance similar changes could appear in MS's CLR? Unfortunately not for 4.0. But this is something we’ll be evaluating for future releases. Thanks, JustinAnonymous
November 05, 2008
Hi Anders, >>>>> Regarding the string class, I'd like to request that string.Contains is overloaded to take params (i.e. "contains all these strings" instead of just one operator). Also string.ContainsAny with params would be nice as it's a very common pattern among developers to check a string for either N or any inclusive instances of other strings. Thanks for the suggestions. We’ll see if we can fit some of these in for 4.0. Thanks, JustinAnonymous
November 05, 2008
Hi Steven, It's a CLI limitation that co/contravariance is supported only on interfaces and delegates. This form of variance is already supported in the CLR and can be used in IL with the +/- notation. Regarding the C# change -- they've added keywords to allow use of variance, but C# (and any .NET language) is limited by the CLI/CLR support. That is, unless they want to add extra support on top, which I understand Eiffel .NET does. At the moment, there are no plans for broader variance support, but if you haven't already, you may want to check out Eric Lippert's blog series on co/contravariance. In the comments sections, you'll see a lot of requests and discussion around broader variance support...and an extended discussion of the issues involved. Thanks, KimAnonymous
November 05, 2008
The comment has been removedAnonymous
November 05, 2008
Obviously I've been looking at the proposed C# 4.0 features pretty carefully, and I promise I'llAnonymous
November 05, 2008
Great news about the tuples. I'm looking forward towards quite a lot of F#/C# mixed code now :) Regarding contracts: are you going to use them throughout the BCL itself (and other parts of the FCL) as well? I recall seeing some seemingly contract-related attributes on the (internal) BigInteger class in 3.5 - more to come? Obviously, contracts, and particularly the static type checking feature - are only truly useful when they are used from top to bottom. Also, since people above remind of some common refactoring requests, let me add one as well: generify more BCL classes! I mean stuff like WeakReference<T>, Type<T>, and so on.Anonymous
November 05, 2008
int19h, We will be adding contracts throughout as much of the BCL as we can in .NET 4.0, but we won't have 100% coverage. We're also getting the rest of the FCL on board. This will be a phased approach over the next couple of releases, where each release will have better coverage throughout .NET and more streamlined tools. We don't have plans to add WeakReference<T> or Type<T> in 4.0, but these (and some other generic types) are things we are considering for the future. Thanks for the suggestions. Thanks, JustinAnonymous
November 05, 2008
Justin, Great feedback and great news. Thanks! AndrewAnonymous
November 06, 2008
Design by Contract with .NET 4.0Anonymous
November 06, 2008
Hi, this sounds all very exciting! > In Process Side-by-Side: support for multiple CLR versions running in the same process. Does this mean that it may be possible to (safely) write shell extensions in .NET starting with 4.0?Anonymous
November 06, 2008
I’ve just found an interesting post with some of the new stuff we’ll have on the next version of theAnonymous
November 06, 2008
I’ve just found an interesting post with some of the new stuff we’ll have on the next version of theAnonymous
November 06, 2008
.NET What's New in the BCL in .NET 4.0 NetMon API – Capture, Parse and and Capture File AccessAnonymous
November 06, 2008
.NETWhat'sNewintheBCLin.NET4.0NetMonAPI–Capture,ParseandandCaptureFileAccess(wi...Anonymous
November 06, 2008
> Does this mean that it may be possible to (safely) write shell extensions in .NET starting with 4.0? ... and MSI custom actions?Anonymous
November 08, 2008
jQuery/ASP.NET/ASP.NET AJAX/ASP.NET MVC Visual Studio patched for better jQuery IntelliSense . Yes! StevenAnonymous
November 08, 2008
YoMan, >>>>> Does this mean that it may be possible to (safely) write shell extensions in .NET starting with 4.0? Right now, we only support in-proc SxS for CLR v2 and v4. So unfortunately it is still not safe to write shell extensions in .NET since you could have a .NET v1.1 app calling a v4 shell extension (which wouldn't work). We're evaluating whether or not we can enable in-proc SxS with 1.0 and 1.1, but have no firm plans at the moment. Thanks, JustinAnonymous
November 08, 2008
int19h, >>>>> ... and MSI custom actions? It may be possible to write a managed MSI custom action with 4.0, but to what extent is currently TBD. In general, the guidance is to avoid custom actions as much as possible (managed or unmanaged), because most installation failures today are attributed to failures inside custom actions. Along those lines, we're actually working to reduce the number of custom actions in the .NET Framework installation as much as we can for 4.0. Thanks, JustinAnonymous
November 09, 2008
The comment has been removedAnonymous
November 09, 2008
Hi Denis, >>>>> And about dynamic code in C# and VBx? The CTP has some features? My post is just about what's new in the BCL and CLR in the CTP, but there's lots of other new stuff throughout the .NET Framework and .NET languages. You may be interested in the following two sessions from the PDC that discuss more about the new enhancements to the next versions of C# and VB: http://channel9.msdn.com/pdc2008/TL16/ http://channel9.msdn.com/pdc2008/TL12/ The VB team also has a nice blog post on the new features in VB 2010: http://blogs.msdn.com/vbteam/archive/2008/11/02/vb-2010-unveiled-at-pdc-2008-lisa-feigenbaum.aspx Hope this helps! Thanks, JustinAnonymous
November 11, 2008
This blog post is to provide a bit more detail about the Code Contracts feature that was recently announcedAnonymous
November 11, 2008
Can I hope for the following issues?
- Zip packer (I know one from Sharp Develop, but better is included in framework
- CAST crypto algorithm
- SNMP support Thanks
Anonymous
November 11, 2008
And also collection for all controls on the form (recursive)? Not only first level for container.Anonymous
November 12, 2008
First showed at the PDC as a part of this Pex session was support for contracts , if you have seen theAnonymous
November 12, 2008
I fully applaud the breaking changes in String, but can you REALLY still justify NOT fixing the IsValid method any longer? Sheesh.Anonymous
November 13, 2008
BCLTeam, "...most installation failures today are attributed to failures inside custom actions." I've seen this same statement made a couple of times before. I think this is comparable to saying 99% of car accidents occur within 10 miles of home. Since 99% of the time you're within 10 miles of home, of course most accidents are going to occur there. I don't see how custom actions can be eliminated unless they become standard actions and I haven't seen any major features added to the Windows Installer in a long time, v2.0 maybe. How do you plan on dealing with this for .NET 4?Anonymous
November 15, 2008
Previously, when covering some of the additions to the .NET 4.0 Framework such as optional and namedAnonymous
November 15, 2008
Previously, when covering some of the additions to the .NET 4.0 Framework such as optional and namedAnonymous
November 19, 2008
I'm glad to hear that covariance may be showing up. I seem to recall thinking that XmlSerializer would be able to serialize IList<> (instead of just IList and List<>) if it had that feature, but I'm not positive (led to an interesting debate on the MSDN forums) Couple of questions on assembly refactoring: in 4.0, is Cache still in System.Web, or has it been moved to an assembly that WinForms/WPF apps normally reference? Also, will XAML be getting moved out of WPF and into a more general-purpose serialization assembly? I had read somewhere both were being considered, but I can't find mention of either with regards to 4.0Anonymous
November 19, 2008
Hi Marc, The BCL team doesn't actually own TypeConverters, but I'm following up with the team that does to see if we can address IsValid in .NET 4.0. Hope this helps. Thanks, JustinAnonymous
November 19, 2008
Hi Keith, Cache is still in System.Web in 4.0, but moving it to a more core location is something on our radar for the future. There will be a general-purpose assembly for XAML serialization in 4.0. Cheers, JustinAnonymous
November 21, 2008
A while ago we announced Visual Studio 2010 and C# 4.0. In case you'd like to catch up and read articlesAnonymous
November 21, 2008
Vous l’avez peut être vu parmi les informations plus ou moins liées à la PDC 2008 : il devrait y avoirAnonymous
November 26, 2008
.NET 4.0 will add the concept of Tuples in the Base Class Library, that will improve interoperabilityAnonymous
December 01, 2008
"What's Next?" - Everybody is interested to know about new and upcoming things. While IAnonymous
December 01, 2008
Are we making the following systems (and some others I forget) provider-based? 1.- Cache (I should be able to use any caching solution I want) 2.- Configuration( I want to read my configuration from a database, memory. etc)Anonymous
December 01, 2008
Good job on improving the file system enumerations. I ran into that problem recently. I look forward to being able to use the more efficient APIs. It would be nice if FileSystemWatcher was fixed also. There are a few different issues with it like the fact that it doesn't raise notifications for all changes if too many occur. Also, if you delete a file from the Command Prompt, the file name is sent in 8.3 format.Anonymous
December 01, 2008
Another thing I would like to see changed is that date/time values should be localized for messages that are written out using TraceSource. It makes it a pain when you are looking at trace logs and attempting to determine when an exception occurred because it's in GMT.Anonymous
December 04, 2008
The comment has been removedAnonymous
December 25, 2008
"What's Next?" - Everybody is interested to know about new and upcoming things. While IAnonymous
December 27, 2008
Hacía tiempo que tenía en el tintero escribir este post en torno a algunas de las novedades que aparecenAnonymous
December 30, 2008
You may have already read Justin Van Patten's post about the upcoming breaking changes to the StringAnonymous
February 12, 2009
A BCL csapat közzétette azokat az új képességeket, amiket a várhatóan ez év második felében megjelenőAnonymous
February 25, 2009
Thank you for submitting this cool story - Trackback from progg.ru