58
votes

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 options 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 ?

5
This would be a great wiki... but in the meantime... +1 because you're only at 78 rep points!Armstrongest
Yes, please switch this to a community wiki - great entry for that!Philip Rieck
There is bug submitted to Microsoft Connect about unintuitive virtual method resolution with optional parametersuser333229

5 Answers

31
votes

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

15
votes

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.

5
votes

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.

2
votes

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.

0
votes

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.