Using Generics causes Dispose() error

G

Guest

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.Junk2.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.JunkControl
{
T myObject;
public Junk2(T junk)
: base()
{
InitializeComponent();
myObject = junk;
}
}
}

namespace TestControl
{
partial class Junk2
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer 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.Dispose();
}
base.Dispose(disposing);
}
}
 
D

Daniel

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.
 
G

Guest

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 said:
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.
 
G

Guest

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 said:
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.
 
D

Daniel

No worries :)



SteveT said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top