question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VB -> C#: injected base breaks overrides

See original GitHub issue

Input code

Private Sub FillAll()
         Clear()
         If Query IsNot Nothing AndAlso Not String.IsNullOrWhiteSpace(Query.CommandText) Then
            ValidateHelper()
            Try
               Using reader = _Helper.ExecuteReader(Query)
                  Dim fieldNames As New List(Of String)
                  For index = 0 To reader.FieldCount - 1
                     fieldNames.Add(reader.GetName(index))
                  Next
                  While reader.Read
                     Dim entity = BuildNewEntity() 
                     entity.InitializeData(reader, fieldNames)
                     AddNewEntity(entity)
                  End While
               End Using
            Catch ex As Exception
               Throw New DataAccessObjectException(SeikaORMClasses.ErrorOnFillAll, ex, Query, Nothing)
            End Try
         End If
      End Sub

BuildNewEntity is defined as this in the parent object:

        protected internal virtual T BuildNewEntity()
        {
            return new T();
        }

A child object redefines BuildNewEntity:

        protected override TestSEntity BuildNewEntity()
        {
            return new TestSEntity(_BusinessCache);
        }

Erroneous output

        private void FillAll()
        {
            Clear();
            if (Query is object && !string.IsNullOrWhiteSpace(Query.CommandText))
            {
                ValidateHelper();
                try
                {
                    using (var reader = _Helper.ExecuteReader(Query))
                    {
                        var fieldNames = new List<string>();
                        for (int index = 0, loopTo = reader.FieldCount - 1; index <= loopTo; index++)
                            fieldNames.Add(reader.GetName(index));
                        while (reader.Read())
                        {
                            var entity = base.BuildNewEntity(); 
                            entity.InitializeData(reader, fieldNames);
                            AddNewEntity(entity);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new DataAccessObjectException(SeikaORMClasses.ErrorOnFillAll, ex, Query, null);
                }
            }
        }

Expected output

        private void FillAll()
        {
            Clear();
            if (Query is object && !string.IsNullOrWhiteSpace(Query.CommandText))
            {
                ValidateHelper();
                try
                {
                    using (var reader = _Helper.ExecuteReader(Query))
                    {
                        var fieldNames = new List<string>();
                        for (int index = 0, loopTo = reader.FieldCount - 1; index <= loopTo; index++)
                            fieldNames.Add(reader.GetName(index));
                        while (reader.Read())
                        {
                            var entity = BuildNewEntity(); 
                            entity.InitializeData(reader, fieldNames);
                            AddNewEntity(entity);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new DataAccessObjectException(SeikaORMClasses.ErrorOnFillAll, ex, Query, null);
                }
            }
        }

Details

  • VS Extension v81.6.0

base should not be introduced when not needed - it will break the behavior silently when override is involved.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
GrahamTheCodercommented, Aug 1, 2020

This is caused by a bug in the Roslyn library - one that I’ve actually had to work around before for a slightly different case. I’ll find a way to workaround this one, and then hopefully actually get around to PRing the fix to Roslyn too.

1reaction
GrahamTheCodercommented, Jul 30, 2020

Thanks, that’s great!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - How to break Execution of an override method from it's ...
One option would be to put all your actual OnNavigatedTo code in a separate method that is called by the base class OnNavigateTo....
Read more >
Overrides - Visual Basic
In this article​​ Specifies that a property or procedure overrides an identically named property or procedure inherited from a base class.
Read more >
C# static code analysis: Overriding members should do ...
This rule ignores overrides of Equals and GetHashCode . NOTE: In some cases it might be dangerous to add or remove empty overrides,...
Read more >
C# static code analysis | clumsy: Overriding members ...
Overriding a method just to call the same method from the base class without performing any other actions is useless and misleading. The...
Read more >
Overrides of Method() should call base.Method()
Typically overrides of a base method, should refine or complete the behavior of the base method. If the base method is not called,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found