Using Generics causes Dispose() error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SteveT

    #1

    Using Generics causes Dispose() error

    I have written a control that does some base functionality. I then wrote a
    control that inherits from it so that I can make several unique versions
    which behave differently. To do this the inherited control uses generics.
    When I compile this code the "Dispose()" routine of my inherited class
    generates a compiler error.

    TestControl.Jun k2.Dispose(bool ): no suitable method found to override.

    Can someone tell me why this is happening and how I can correct it?

    Sample code below.

    namespace TestControl
    {
    public partial class Junk2<T: TestControl.Jun kControl
    {
    T myObject;
    public Junk2(T junk)
    : base()
    {
    InitializeCompo nent();
    myObject = junk;
    }
    }
    }

    namespace TestControl
    {
    partial class Junk2
    {
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.Componen tModel.IContain er components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing ">true if managed resources should be
    disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
    if (disposing && (components != null))
    {
    components.Disp ose();
    }
    base.Dispose(di sposing);
    }
    }
    --
    -----------
    Thanks,
    Steve
  • Daniel

    #2
    Re: Using Generics causes Dispose() error

    Well its telling you the parent class doesnt have a dispose method marked as
    protected that it can override, if are inheriting from a control i am
    presuming your next class down doesnt have dispose in it and the next one
    down from that does.


    "SteveT" <SteveT@newsgro ups.nospamwrote in message
    news:D4E9B344-334A-4FB8-AB02-208DEC063D1B@mi crosoft.com...
    >I have written a control that does some base functionality. I then wrote a
    control that inherits from it so that I can make several unique versions
    which behave differently. To do this the inherited control uses generics.
    When I compile this code the "Dispose()" routine of my inherited class
    generates a compiler error.
    >
    TestControl.Jun k2.Dispose(bool ): no suitable method found to override.
    >
    Can someone tell me why this is happening and how I can correct it?
    >
    Sample code below.
    >
    namespace TestControl
    {
    public partial class Junk2<T: TestControl.Jun kControl
    {
    T myObject;
    public Junk2(T junk)
    : base()
    {
    InitializeCompo nent();
    myObject = junk;
    }
    }
    }
    >
    namespace TestControl
    {
    partial class Junk2
    {
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.Componen tModel.IContain er components = null;
    >
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing ">true if managed resources should be
    disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
    if (disposing && (components != null))
    {
    components.Disp ose();
    }
    base.Dispose(di sposing);
    }
    }
    --
    -----------
    Thanks,
    Steve

    Comment

    • SteveT

      #3
      Re: Using Generics causes Dispose() error

      The base class JunkControl inherits from Control and therefore it has its own
      Dispose() routine. It's definition is identical to the Junk2 method. That
      code is autogenerated by the compiler. How do I fix this?


      --
      -----------
      Thanks,
      Steve


      "Daniel" wrote:
      Well its telling you the parent class doesnt have a dispose method marked as
      protected that it can override, if are inheriting from a control i am
      presuming your next class down doesnt have dispose in it and the next one
      down from that does.
      >
      >
      "SteveT" <SteveT@newsgro ups.nospamwrote in message
      news:D4E9B344-334A-4FB8-AB02-208DEC063D1B@mi crosoft.com...
      I have written a control that does some base functionality. I then wrote a
      control that inherits from it so that I can make several unique versions
      which behave differently. To do this the inherited control uses generics.
      When I compile this code the "Dispose()" routine of my inherited class
      generates a compiler error.

      TestControl.Jun k2.Dispose(bool ): no suitable method found to override.

      Can someone tell me why this is happening and how I can correct it?

      Sample code below.

      namespace TestControl
      {
      public partial class Junk2<T: TestControl.Jun kControl
      {
      T myObject;
      public Junk2(T junk)
      : base()
      {
      InitializeCompo nent();
      myObject = junk;
      }
      }
      }

      namespace TestControl
      {
      partial class Junk2
      {
      /// <summary>
      /// Required designer variable.
      /// </summary>
      private System.Componen tModel.IContain er components = null;

      /// <summary>
      /// Clean up any resources being used.
      /// </summary>
      /// <param name="disposing ">true if managed resources should be
      disposed; otherwise, false.</param>
      protected override void Dispose(bool disposing)
      {
      if (disposing && (components != null))
      {
      components.Disp ose();
      }
      base.Dispose(di sposing);
      }
      }
      --
      -----------
      Thanks,
      Steve
      >
      >
      >

      Comment

      • SteveT

        #4
        Re: Using Generics causes Dispose() error

        You got me to looking more. Thanks. What I found was interesting.

        If I create a plan CS code file and create my inherited class it works just
        fine. If I use the "inherit control" method when adding a new item it
        generates that extra Dispose code in the backgroud. I'll use the first
        method for now on.

        Thanks for the help.
        --
        -----------
        Thanks,
        Steve


        "Daniel" wrote:
        Well its telling you the parent class doesnt have a dispose method marked as
        protected that it can override, if are inheriting from a control i am
        presuming your next class down doesnt have dispose in it and the next one
        down from that does.
        >
        >
        "SteveT" <SteveT@newsgro ups.nospamwrote in message
        news:D4E9B344-334A-4FB8-AB02-208DEC063D1B@mi crosoft.com...
        I have written a control that does some base functionality. I then wrote a
        control that inherits from it so that I can make several unique versions
        which behave differently. To do this the inherited control uses generics.
        When I compile this code the "Dispose()" routine of my inherited class
        generates a compiler error.

        TestControl.Jun k2.Dispose(bool ): no suitable method found to override.

        Can someone tell me why this is happening and how I can correct it?

        Sample code below.

        namespace TestControl
        {
        public partial class Junk2<T: TestControl.Jun kControl
        {
        T myObject;
        public Junk2(T junk)
        : base()
        {
        InitializeCompo nent();
        myObject = junk;
        }
        }
        }

        namespace TestControl
        {
        partial class Junk2
        {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.Componen tModel.IContain er components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing ">true if managed resources should be
        disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
        if (disposing && (components != null))
        {
        components.Disp ose();
        }
        base.Dispose(di sposing);
        }
        }
        --
        -----------
        Thanks,
        Steve
        >
        >
        >

        Comment

        • Daniel

          #5
          Re: Using Generics causes Dispose() error

          No worries :)



          "SteveT" <SteveT@newsgro ups.nospamwrote in message
          news:64E79B27-CFD5-44F2-8D99-3EC04C8C5CDB@mi crosoft.com...
          You got me to looking more. Thanks. What I found was interesting.
          >
          If I create a plan CS code file and create my inherited class it works
          just
          fine. If I use the "inherit control" method when adding a new item it
          generates that extra Dispose code in the backgroud. I'll use the first
          method for now on.
          >
          Thanks for the help.
          --
          -----------
          Thanks,
          Steve
          >
          >
          "Daniel" wrote:
          >
          >Well its telling you the parent class doesnt have a dispose method marked
          >as
          >protected that it can override, if are inheriting from a control i am
          >presuming your next class down doesnt have dispose in it and the next one
          >down from that does.
          >>
          >>
          >"SteveT" <SteveT@newsgro ups.nospamwrote in message
          >news:D4E9B34 4-334A-4FB8-AB02-208DEC063D1B@mi crosoft.com...
          >I have written a control that does some base functionality. I then
          >wrote a
          control that inherits from it so that I can make several unique
          versions
          which behave differently. To do this the inherited control uses
          generics.
          When I compile this code the "Dispose()" routine of my inherited class
          generates a compiler error.
          >
          TestControl.Jun k2.Dispose(bool ): no suitable method found to override.
          >
          Can someone tell me why this is happening and how I can correct it?
          >
          Sample code below.
          >
          namespace TestControl
          {
          public partial class Junk2<T: TestControl.Jun kControl
          {
          T myObject;
          public Junk2(T junk)
          : base()
          {
          InitializeCompo nent();
          myObject = junk;
          }
          }
          }
          >
          namespace TestControl
          {
          partial class Junk2
          {
          /// <summary>
          /// Required designer variable.
          /// </summary>
          private System.Componen tModel.IContain er components = null;
          >
          /// <summary>
          /// Clean up any resources being used.
          /// </summary>
          /// <param name="disposing ">true if managed resources should be
          disposed; otherwise, false.</param>
          protected override void Dispose(bool disposing)
          {
          if (disposing && (components != null))
          {
          components.Disp ose();
          }
          base.Dispose(di sposing);
          }
          }
          --
          -----------
          Thanks,
          Steve
          >>
          >>
          >>

          Comment

          Working...