Why is this code compiled in VS2005 but not VS2008 (VB.NET)

I am migrating a VB.NET web application from Visual Studio 2005 (.NET 2.0) to Visual Studio 2008 (.NET 3.5), and although it was basically simple, I ran into a problem that took some time to resolve.

The code in question says:

Dim serviceArray = New SecurityLayer.Model.Service()
serviceArray = new SecurityLayer.SecurityBusinessController.GetServices(userId)

Which compiles in VS2005 / .NET2.0, but crashes in VS2008 / .NET3.5 with the following error:

A value of type "1-dimensional array SecurityLayer.Model.Service" cannot be converted to "SecurityLayer.Model.Service"

This indicates that serviceArray is not declared as an array, and while reading the MSDN documentation, it does not look like the syntax has changed between versions, but it does indicate that curly braces are needed, regardless of whether any values ​​are passed or not. Of course, adding curly braces to this declaration solves the problem (and the compiler moves on to the next instance!).

Dim serviceArray = New SecurityLayer.Model.Service(){}
serviceArray = new SecurityLayer.SecurityBusinessController.GetServices(userId)

After updating all instances of this declaration, the code now builds and works as expected.

Option Explicit and Option Strict are the same in both IDEs, so this cannot be (or at least what I assume).

So my question is: why was this created in VS2005 / .NET2.0, and not in VS2008 / .NET3.5?

Thanks in advance

+3
1

VB.NET 9 . Dim , serviceArray Object. , , serviceArray Service. .

+6

Source: https://habr.com/ru/post/1733508/


All Articles