开发者

Breaking changes in .NET 4.0

There is a lot of information about new features and classes in new 4.0 however there are also changes that may affect existing applications, for example

  1. Timespan now implements IFormattable and old string.Format() with invalid o开发者_如何转开发ptions will throw exception instead of calling simple ToString(). However, CLR team provides a nice feature to enable behaviour from previous version with configuration setting - TimeSpan_LegacyFormatMode .

    CLR Inside Out

  2. Access to events inside the class where they are declared using += or -= will lead to call add/remove generated accessors that return void. Some code won't even compile in 4.0.

    Chris Burrows Blog

  3. CAS is deprecated and to enable it one still need to use special setting in configuration - NetFx40_LegacySecurityPolicy

So I wonder what are other changes and is it possible to find at least preliminary list of changes that will or may break existing functionality with release of .NET 4.0 ?


The languages documentation team publishes separate documents for C# and VB breaking changes:

VB: http://msdn.microsoft.com/en-us/library/cc714070%28VS.100%29.aspx

C#: http://msdn.microsoft.com/en-us/library/ee855831%28VS.100%29.aspx

I wrote the C# one and included covariance and contravariance breaking changes mentioned by Eric Lippert, and events changes discussed by Chris Burrows. There are also some breaking changes around optional parameters, embedded interop types, and method group type inference.

Update:

One more useful document (from .NET documentation team): http://msdn.microsoft.com/en-us/library/ee941656%28VS.100%29.aspx


Covariant and contravariant conversions introduce some obscure but possible breaking changes upon recompilation:

http://blogs.msdn.com/ericlippert/archive/2007/11/02/covariance-and-contravariance-in-c-part-nine-breaking-changes.aspx

The C# user education team compiles a list of the known potential breaking changes in the new version of the compiler, see the answer above for details.


Also note that SmtpClient now implements IDisposable so you should now use something like this:

using (var smtpclient = new SmtpClient())
{
  smtpclient.Send(message);
} 

According to this page there might be more of these 'hidden jams' inside the .NET 4.0 framework. And the author suggest to find them by using FxCop on your code.


Just to add to the list, here's the ASP.Net official list for the RC, I haven't come across an RTM one yet.


I've just fixed a bug in a production app which recently moved to .NET 4.0.

Data binding that uses nested properties was throwing:

ArgumentException: Cannot bind to the property or column 'SomeProperty' on the DataSource.

It appears to be a known issue with a workaround. I couldn't find it on any official lists and the bug on Microsoft Connect has been closed as "Not Reproducible".

The nested properties are all defined in strings so I had to search for them all manually.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜