none
Broken code/run-time errors in older code RRS feed

  • Question

  • I picked up a project I've worked on until 2011, and had some issues running it under the most recent version of VS (2017).

    Although it compiled OK, I had some issues during run-time:

    - .ToString on a custom class/structure had no need to be overridden to show the correct content, now it has to be

    - xx = New BindingSource (xxx.DataSource) now needs a second argument (DataMember as string) to take the overload where the first argument is a DataSource, if not, it expects an iContainer.

    Question: is there somewhere an overview of issues due to changes in the versions of VS, so I can anticipate them rather then having to retest every line of code to see if there are no run-time errors?

    I can understand that sometimes backward compatibility is a bitch, and some changes/evolutions are unavoidable, but when opening a project in a recenter version of VS, they should be pointed out to the programmer.

    There is also the issue of the "can be simplified"s where if the proposed "simplification" results in an error...

    example:

    Dim pdlg As New PrintDialog With {.PrinterSettings = PrintInv.PrinterSettings}

    simplified to:

    Dim pdlg As New PrintDialog With {PrintInv.PrinterSettings}

    states: ... must start with a '.'

    Sunday, February 18, 2018 5:58 AM

All replies

  • Although it compiled OK, I had some issues during run-time:

    - .ToString on a custom class/structure had no need to be overridden to show the correct content, now it has to be

    - xx = New BindingSource (xxx.DataSource) now needs a second argument (DataMember as string) to take the overload where the first argument is a DataSource, if not, it expects an iContainer.

    There is something else going on.  Both examples you quote are unchanged from Framework 2.0, which is well before 2011.

    https://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.bindingsource(v=vs.80).aspx
    https://msdn.microsoft.com/en-us/library/system.object.tostring(v=vs.80).aspx

    Sunday, February 18, 2018 7:17 AM
  • I worked until 2011 on that project, but if I remember well, it was on Framework 1.1.

    Sunday, February 18, 2018 9:14 AM
  • Danny,

    Since version VB7 (Visual Studio.Net) there are no breaking changes until now VB15(Visual.Studio 2017)

    Of course hardware and OS can have been changed.

    By the way Framework 1.1 was VB7.1 (. Net 2003) but that framework is probably not on your computer. 

    However, this code is since version 2008 

    Dim pdlg As New PrintDialog With {.PrinterSettings = PrintInv.PrinterSettings}

    And this code has never been 

     
    Dim pdlg As New PrintDialog With {PrintInv.PrinterSettings}
    Therefore why are you telling "they should be pointed out to the programmer" if there is nothing to tell. 


    Success
    Cor

    Sunday, February 18, 2018 9:30 AM
  • Hi Cor, thx, but...

    What other explanation why an unchanged source, on a totally different computer, gives the issues that I described...

    As for the printdialog-example: it is what the IDE proposes as a simplification, but if 'preview/apply' is done, what you rightfully name 'has never been', is what the IDE makes of it.

    Sunday, February 18, 2018 9:35 AM
  • It tells you that PrintInv does not exist. But that is not a VB part, it should be made in code.

    I guess it is because you have not added the powerpack to your current Visual Studio

    https://docs.microsoft.com/en-us/dotnet/visual-basic/developing-apps/windows-forms/power-packs-controls


    Success
    Cor


    Sunday, February 18, 2018 10:14 AM
  • Hello Danny,

    I would need to know more about the BindingSource issue as there are zero changes to cause this behavior when used in a conventional manner so you may not be or something else is going on.

    Visual Studio's IDE is pretty good at suggestions yet can give you suggestions that are incorrect.

    In the following example we have .ConnectionString which is a property of SqlCommand and ConnectionString which is a base property for a custom class.

    Here we have a suggestion from the IDE that is a) grayed out b) has triple dots.

    Now look at the suggestion, note it's not easy to see but the change is already flagged as a problem hence we should not make the suggested change because it will give us invalid code.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, February 18, 2018 10:31 AM
    Moderator
  • Did install the powerpack now, but no changes on any of the issues.

    Regarding the 'simplified' issue: bit odd that the IDE proposes a solution knowing it is a bad one.

    I thought the red was an indication of what was and green/grey of what should be...

    indeed, you can see already a little bit of the error underlining in the green/grey line, so knowing it is wrong, why bothering proposing it... I don't like to suppress it, as it may hide good simplifications

    Regarding the binding source issue, I can only think that before a ctype() or so was implicitly done of another override with Datasource as only argument was present.

    As the function I call from many places in the code nowhere has a second argument to pass nor had the called code (Dim bs As New BindingSource(dgv.DataSource)) a second argument (until now as it fails in run-time (Dim bs As New BindingSource(dgv.DataSource, dgv.DataMember))

    Here the whole sub: (called to reposition in a datagridview after returning from a details-form)

    Public Sub RePositionDgv(ByRef dgv As DataGridView, ByVal KeyValue As Integer, Optional ByVal KeyField As String = "ID", Optional ByVal column As Integer = -1)
            'as this may be called for sorting or after deletion/insert, make sure the required row is existing
            Dim bs As New BindingSource(dgv.DataSource, dgv.DataMember)
            Dim pos As Integer = bs.Find(KeyField, KeyValue)
            If pos > -1 Then
                'if a column was selected, reselect it
                If column > -1 Then
                    dgv.CurrentCell = dgv.Rows(pos).Cells(column)
                Else
                    'can't select/click on hidden field, so get first visible one
                    For c As Integer = 0 To dgv.Rows(0).Cells.Count - 1
                        If dgv.Rows(pos).Cells(c).Visible Then
                            dgv.CurrentCell = dgv.Rows(pos).Cells(c)
                            Exit For
                        End If
                    Next
                End If
            End If
        End Sub

    Sunday, February 18, 2018 11:09 AM
  • Not seeing what you are running into these issues yet wanted to make a suggestion on repositioning.

    Going with your last code block, I would consider the following.

    Public Module BindingSourceExtensions
        <Runtime.CompilerServices.Extension>
        Public Function Reposition(
            ByVal pBindingSource As BindingSource,
            ByVal pColumnName As String,
            ByVal pValue As Object) As Boolean
    
            Dim index As Integer = pBindingSource.Find(pColumnName, pValue)
    
            If index > -1 Then
                pBindingSource.Position = index
                Return True
            Else
                Return False
            End If
    
        End Function
    End Module
    

    To put things into perspective here is how data is loaded

    Form code

    Public Class Form1
        Private bsCustomers As New BindingSource
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            If Not String.IsNullOrWhiteSpace(txtFieldName.Text) Then
                bsCustomers.Reposition(cboColumnNames.Text, txtFieldName.Text)
            End If
        End Sub
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim ops As New DataOperations
    
            bsCustomers.DataSource = ops.CustomerView
            If ops.IsSuccessFul Then
                DataGridView1.DataSource = bsCustomers
                cboColumnNames.DataSource = ops.ColumnNames
            Else
                Button1.Enabled = False
            End If
    
        End Sub
    End Class
    

    In the next code block, BaseSqlServerConnections is mine which simply handles connection to a database along with implementing base exception handling, neither are relevant here.

    Imports System.Data.SqlClient
    Public Class DataOperations
        Inherits BaseSqlServerConnections
        Public Sub SetConnectionString(
            ByVal pDatabaseServer As String,
            ByVal pDefaultCatalog As String)
    
            DatabaseServer = pDatabaseServer
            DefaultCatalog = pDefaultCatalog
    
        End Sub
        Public Sub SetCatalog(ByVal pDefaultCatalog As String)
            DefaultCatalog = pDefaultCatalog
        End Sub
        Public Function ColumnNames() As List(Of String)
            Return New List(Of String) From
                {"CompanyName", "ContactName", "ContactTitle"}
        End Function
        Public Function CustomerView() As DataTable
            mHasException = False
            mHasSqlException = False
    
            Dim dt As New DataTable
            Dim selectStatement As String = $"SELECT {String.Join(",", ColumnNames.ToArray)} " &
                "FROM Customers"
    
            Try
                Using cn = New SqlConnection() With {.ConnectionString = ConnectionString}
                    Using cmd = New SqlCommand() With {.Connection = cn, .CommandText = selectStatement}
                        cmd.CommandText = selectStatement
                        cn.Open()
                        dt.Load(cmd.ExecuteReader)
                    End Using
                End Using
    
            Catch sex As SqlException
                mHasSqlException = True
                mSqlException = sex
            Catch ex As Exception
                mHasException = True
                mLastException = ex
            End Try
    
            Return dt
        End Function
    End Class
    

    Before using the extension method to find Around the Horn, I'm positioned on the last column.

    After pressing button1, still on the same column


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Sunday, February 18, 2018 11:52 AM
    Moderator
  • Do you have the latest version of VS 2017 (15.5.6)?  Some of what you describe sounds like it might be an analyzer issue.  I've had some funkiness in the 15.3 release with analyzers misbehaving in odd ways.

    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"


    Sunday, February 18, 2018 6:14 PM
    Moderator
  • Here about/copy info: (I have 15.5.2 it seems)

    Microsoft Visual Studio Community 2017
    Version 15.5.2
    VisualStudio.15.Release/15.5.2+27130.2010
    Microsoft .NET Framework
    Version 4.7.02556

    Installed Version: Community
    Visual Basic 2017   00369-60000-00001-AA191
    Microsoft Visual Basic 2017
    Visual C# 2017   00369-60000-00001-AA191
    Microsoft Visual C# 2017
    Visual C++ 2017   00369-60000-00001-AA191
    Microsoft Visual C++ 2017
    Visual F# 4.1   00369-60000-00001-AA191
    Microsoft Visual F# 4.1
    Application Insights Tools for Visual Studio Package   8.10.01106.1
    Application Insights Tools for Visual Studio
    ASP.NET and Web Tools 2017   15.0.31125.0
    ASP.NET and Web Tools 2017
    ASP.NET Core Razor Language Services   1.0
    Provides languages services for ASP.NET Core Razor.
    ASP.NET Web Frameworks and Tools 2017   5.2.51007.0
    For additional information, visit https://www.asp.net/
    Azure App Service Tools v3.0.0   15.0.31106.0
    Azure App Service Tools v3.0.0
    Azure Data Lake Node   1.0
    This package contains the Data Lake integration nodes for Server Explorer.
    Azure Data Lake Tools for Visual Studio   2.2.9000.1
    Microsoft Azure Data Lake Tools for Visual Studio
    Azure Data Lake Tools for Visual Studio   2.2.9000.1
    Microsoft Azure Data Lake Tools for Visual Studio
    Common Azure Tools   1.10
    Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
    JavaScript Language Service   2.0
    JavaScript Language Service
    JavaScript Project System   2.0
    JavaScript Project System
    JavaScript UWP Project System   2.0
    JavaScript UWP Project System
    Merq   1.1.17-rc (cba4571)
    Command Bus, Event Stream and Async Manager for Visual Studio extensions.
    Microsoft Azure HDInsight Azure Node   2.2.9000.1
    HDInsight Node under Azure Node
    Microsoft Azure Hive Query Language Service   2.2.9000.1
    Language service for Hive query
    Microsoft Azure Stream Analytics Language Service   2.2.9000.1
    Language service for Azure Stream Analytics
    Microsoft Azure Stream Analytics Node   1.0
    Azure Stream Analytics Node under Azure Node
    Microsoft Azure Tools   2.9
    Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.51120.3
    Microsoft Continuous Delivery Tools for Visual Studio   0.3
    Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.
    Microsoft JVM Debugger   1.0
    Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
    Microsoft MI-Based Debugger   1.0
    Provides support for connecting Visual Studio to MI compatible debuggers
    Microsoft Visual C++ Wizards   1.0
    Microsoft Visual C++ Wizards
    Microsoft Visual Studio Tools for Containers   1.1
    Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.
    Microsoft Visual Studio VC Package   1.0
    Microsoft Visual Studio VC Package
    Mono Debugging for Visual Studio   4.8.4-pre (3fe64e3)
    Support for debugging Mono processes with Visual Studio.
    NuGet Package Manager   4.5.0
    NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.
    SQL Server Data Tools   15.1.61710.120
    Microsoft SQL Server Data Tools
    ToolWindowHostedEditor   1.0
    Hosting json editor into a tool window
    TypeScript Tools   15.5.11025.1
    TypeScript Tools for Microsoft Visual Studio
    Visual Studio Code Debug Adapter Host Package   1.0
    Interop layer for hosting Visual Studio Code debug adapters in Visual Studio
    Visual Studio Tools for CMake   1.0
    Visual Studio Tools for CMake
    Visual Studio Tools for Unity   3.5.0.2
    Visual Studio Tools for Unity
    Visual Studio Tools for Universal Windows Apps   15.0.27128.01
    The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.
    VisualStudio.Mac   1.0
    Mac Extension for Visual Studio
    Xamarin   4.8.0.753 (6575bd113)
    Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
    Xamarin Designer   4.8.188 (c5813fa34)
    Visual Studio extension to enable Xamarin Designer tools in Visual Studio.
    Xamarin.Android SDK   8.1.0.25 (HEAD/d8c6e504f)
    Xamarin.Android Reference Assemblies and MSBuild support.
    Xamarin.iOS and Xamarin.Mac SDK   11.6.1.2 (6857dfc)
    Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
    Sunday, February 18, 2018 6:19 PM
  • Try updating VS then, and see if the problems persist on the original copy of the project.

    There should be an update notification when you click on the Flag icon to the right of the title bar.  Or just rerun the installer and it should offer you the update under your current installations.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Sunday, February 18, 2018 6:22 PM
    Moderator
  • The VS update and manual reversing the changes don't change a thing.

    The original code is something I will have to work on as it is on the hard drive of my crashed pc

    I'll get back as soon I have an opportunity to recover it.

    thx

    Sunday, February 18, 2018 8:05 PM