473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.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);
}
}
--
-----------
Thanks,
Steve
Oct 5 '06 #1
4 7999
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" <St****@newsgroups.nospamwrote in message
news:D4**********************************@microsof t.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.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);
}
}
--
-----------
Thanks,
Steve

Oct 5 '06 #2
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" <St****@newsgroups.nospamwrote in message
news:D4**********************************@microsof t.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.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);
}
}
--
-----------
Thanks,
Steve


Oct 5 '06 #3
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" <St****@newsgroups.nospamwrote in message
news:D4**********************************@microsof t.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.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);
}
}
--
-----------
Thanks,
Steve


Oct 5 '06 #4
No worries :)

"SteveT" <St****@newsgroups.nospamwrote in message
news:64**********************************@microsof t.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" <St****@newsgroups.nospamwrote in message
news:D4**********************************@microso ft.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.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);
}
}
--
-----------
Thanks,
Steve



Oct 5 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Junior | last post by:
I keep receiving this "The type or namespace name 'CASsEventHandler' could not be found (are you missing a using directive or an assembly reference?)" message in two particular lines, and I've...
11
by: andrew queisser | last post by:
I've read some material on the upcoming Generics for C#. I've seen two types of syntax used for constraints: - direct specification of the interface in the angle brackets - where clauses I...
3
by: scoobydoo | last post by:
Hello, I am trying to implement ICloneable's Clone() function, using Serialization. However, my code causes an exception. I have a class derived from TreeNode called "Node1". In Node1, I...
3
by: Tom Jastrzebski | last post by:
Hello everybody, Here is another problem with generics I come across. Let's say I want to implement a structure performing some operations on some numeric type. I can not than just return...
3
by: Jeff Louie | last post by:
Here is my try at generics. This creates a collection that implements IInvoke and IDisposable and Adds types that implement IInvoke and IDisposable. When the collection goes out of using scope...
4
by: Gazarsgo | last post by:
This seems to be a bit of a contradiction, but how can I construct a Generic class using a System.Type variable that is assigned at run time? Is there some parallel to the Generics concept that...
19
by: Fernando Cacciola | last post by:
I'm puzzled, Why and how _exactly_ is this: void Foo<T>(T v ) where T : Interface/Value/Class/class any better than this void Foo( Interface/Value/Class/object v )
6
by: Mark Rae | last post by:
Hi, I'm in the process of updating an ASP.NET v1.1 web app to v2. The app uses ActiveDirectory a great deal, and I'm trying to use the new System.Collections.Generic namespace where possible,...
6
by: Gina_Marano | last post by:
Hey All, I am using multiple child threads per main thread to download files. It sometimes appears as if the same file is being downloaded twice. I am using "lock". Am I using it correctly? Any...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.