Visual Basic 2008 Breaking Changes

The following table lists all the changes that might prevent an application that was created in Visual Studio 2005 from compiling in Visual Studio 2008, or that might change its run-time behavior.

Category

Issue

Description

Nullable types

T widening to T? is a predefined conversion in Visual Studio 2008.

In Visual Studio 2005, you can create a user-defined conversion to enable T to widen to Nullable(Of T). As part of the increased support for nullable types in Visual Studio 2008, this conversion is predefined.

Because overload resolution considers both predefined and user-defined conversions, there is a potential ambiguity if both exist. Therefore, code that contains a user-defined widening conversion from T to T? is potentially ambiguous in Visual Studio 2008.

For example, in the following code, the call to c3.Sub1 works in Visual Studio 2005 but causes a compiler error in Visual Studio 2008.

To resolve this issue, you can remove the user-defined conversion, or you can explicitly cast to Class1 or Class2:

Overload resolution

Overload resolution differences between generic and non-generic classes have been corrected.

A bug in Visual Studio 2005 can cause overload resolution behavior for generic classes to be different from that of non-generic classes. In the following example, Class1 and Class2 are identical except that Class2 has a generic parameter defined on it. The call to c1.Sub1 in Main is ambiguous because the argument passed in could bind to either overload of Sub1 in Class1. The ambiguity causes a compiler error in both Visual Studio 2005 and Visual Studio 2008.

The call to c2.Sub1 should generate the same error, but in Visual Studio 2005 it does not. Instead, the method binds to the unconstrained overload of Sub1 in Class2.

This issue is fixed in Visual Studio 2008. Both calls generate compiler errors because of the ambiguity. This is illustrated in the following code:

To resolve this issue, you can change the overloads so that they are no longer ambiguous, or you can specify the type arguments explicitly:

Overload resolution

Overload resolution with generic and ParamArray parameters produces different results in Visual Studio 2008.

The goal of overload resolution is to try to select the candidate method whose parameters most closely match the types of the arguments that are passed to the method. In the example in this section, Sub1 is overloaded across an inheritance hierarchy, and is called with arguments of type Integer and Short.

Overload resolution rules in both Visual Studio 2005 and Visual Studio 2008 specify that direct matches are better matches than those requiring ParamArray parameters. However, using Visual Studio 2005 overload resolution rules, type inference fails for the overload candidate in the derived class, Class2, because Y cannot be both an Integer and a Short, and exact matches are required. If arguments sh and n were of the same type, the Sub1 in Class2 would be preferred over the candidate in Class1, which has a ParamArray parameter. However, because the two arguments have different types, the base class overload in Class1 is selected instead. T is inferred as Integer, and Short widens into the ParamArrayp.

Visual Studio 2008 uses a new algorithm that selects the same overloads as Visual Studio 2005, except in this specific case. In Visual Studio 2008, the algorithm determines that Integer is the dominant type in this example, because Short widens to Integer. Type parameter Y in the derived class is inferred to be Integer, and Short widens to Integer. As a result, the Sub1 in the derived class is called.

You can force Visual Studio 2005 behavior by casting variable c2 to type C1ass1 before you call Sub1, or by passing argument sh as an array.

See Also

Concepts

Overload Resolution

Nullable Value Types

Generic Types in Visual Basic

Reference

ParamArray

Change History

Date

History

Reason

July 2008

Added topic.

Information enhancement.