locked
Migration from 1.1 to 4.5.2 .Net framework : Method overriden error RRS feed

  • Question

  • Hi,

    I have code in 1.1 framework which is working fine. However, when the same code is migrated into 4.5.2 framework, its giving error.

    code description - There is one abstract method BuildSelectCommand() with return type "IDbCommandWriter" in the base class. When this method is being overriding in derived claass then it gives error - 

    Error description  - BuildSelectCommand()': return type must be IDbCommandWriter to match overridden member BaseBusinessEntity.BuildSelectCommand()


    Code example as below -

            

     [Serializable]
    public abstract class BaseBusinessEntity
    {

        public BaseBusinessEntity()
        {

        }
        protected void DoSearch()
        {
            IDbCommandWriter cWriter = BuildSelectCommand();
        }
        protected abstract IDbCommandWriter BuildSelectCommand();

    }  

    [Serializable]
    public abstract class BusinessEntity : BaseBusinessEntity
    {

        public BusinessEntity()
        {
           
        }
    }


    [Serializable]
    public class Class1 : BusinessEntity
    {

        IDbCommandWriter cw = null;


        protected override IDbCommandWriter BuildSelectCommand()
        {
            return cw;
        }

    }

    Please note that this logic/code architecture has been tested in 4.5.2 seperatly and its working fine but its not working for migrated code.

    Please let me know the root cause of this issue and how can we resolve this.

    Tuesday, February 9, 2016 6:41 AM

Answers

  • There is no such interface in .NET which means it is part of your code somewhere. Is that interface defined in the same assembly as the 2 types that you are using?  If not then you probably missed updating one of the assemblies.  This is something that can occur when you are indirectly referencing an assembly because it is a dependency of an assembly you are directly referencing. 

    Also look for errors earlier in compilation as they can cause the wrong definition to be used. Click each of the overrides and verify it takes you to the correct definition in the assembly that is targeting 4.5.2.

    Michael Taylor
    http://blogs.msmvps.com/p3net

    • Proposed as answer by Kristin Xie Monday, February 22, 2016 7:04 AM
    • Marked as answer by Kristin Xie Tuesday, February 23, 2016 1:21 AM
    Tuesday, February 9, 2016 4:44 PM

All replies

  • Check your referenced assemblies which are listed in Solution Explorer. Also check your sources. Make sure that the classes use the same IDbCommandWriter. Maybe there is a different one in an older DLL or in a namespace. Select these words and press <F12>, perhaps Visual Studio will help you to identify the problem.

    Tuesday, February 9, 2016 7:54 AM
  • I have mentioned already that the same code is working fine in 1.1 framework and same code migrated into 4.5.2 with all assemblies. There is no change in any class or member name, everthing is same. Also, the return type is same as it is declared in base abstract method - IDbCommandWriter.

    Please let me know if there is any difference in inhertence logic in 1.1 and 4.5.2 framework.

    Tuesday, February 9, 2016 12:34 PM
  • There is no such interface in .NET which means it is part of your code somewhere. Is that interface defined in the same assembly as the 2 types that you are using?  If not then you probably missed updating one of the assemblies.  This is something that can occur when you are indirectly referencing an assembly because it is a dependency of an assembly you are directly referencing. 

    Also look for errors earlier in compilation as they can cause the wrong definition to be used. Click each of the overrides and verify it takes you to the correct definition in the assembly that is targeting 4.5.2.

    Michael Taylor
    http://blogs.msmvps.com/p3net

    • Proposed as answer by Kristin Xie Monday, February 22, 2016 7:04 AM
    • Marked as answer by Kristin Xie Tuesday, February 23, 2016 1:21 AM
    Tuesday, February 9, 2016 4:44 PM