Breaking changes in .NET 4.0
Asked Answered
H

5

58

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 ?

Healey answered 30/3, 2010 at 19:37 Comment(1)
There is bug submitted to Microsoft Connect about unintuitive virtual method resolution with optional parametersAssort
A
32

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

Atomy answered 31/3, 2010 at 21:49 Comment(0)
I
15

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.

Isomerism answered 30/3, 2010 at 22:19 Comment(0)
P
5

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.

Puzzle answered 30/3, 2010 at 19:37 Comment(0)
K
2

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.

Kaneshakang answered 30/3, 2010 at 19:41 Comment(0)
M
0

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.

Morez answered 30/3, 2010 at 19:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.