Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I keep trying to compile but I keep getting the error
'PTZ_Camera_Motion_Control01.Form1.Dispose(bool)':no suitable method found to override
I've been searching for answers on the web and tried them but the error still resides.
I'm using .NET Framework 4. The code is below. I'll really appreciate any help I can get on this. Thank you.


/////Form1.cs///////
C#
namespace PTZ_Camera_Motion_Control01
{
    public partial class Form1 : Form 
    { 
        public Form1()
        {
            InitializeComponent();
        }
    }
}


///////Form1.Designer.cs///////
C#
namespace PTZ_Camera_Motion_Control01
{
    partial class Form1
    {
        private System.ComponentModel.IContainer components = null;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
        private void InitializeComponent()
        { .....}
     }
}
Posted
Updated 9-Sep-15 18:17pm
v3
Comments
Sergey Alexandrovich Kryukov 9-Sep-15 23:08pm    
You are messing up something. Are you sure that "Form" in your sample is really System.Windows.Forms.Form? If so, it really has protected override void Dispose(bool).
By the way, what's the purpose of overriding this method?
—SA
Member 11972608 9-Sep-15 23:23pm    
Yeah I'm sure it is System.Windows.Forms.Form. I even tried replacing Form with System.Windows.Forms.Form to make sure. But still got the same error.
I'm using Dispose is to free unmanaged resources. It needs to be done at some point, otherwise they will never be cleaned up.
Sergey Alexandrovich Kryukov 10-Sep-15 0:14am    
Then your information is inadequate; maybe the compilation error is in some different line, or the code shown is not the same code which shows the error. You did not even comment the code line. You don't show adequate part of code, for example, did not show "using". Comment it: "the error is on this line"... Is it really in the code generated by the designer? Please understand: the error is way too trivial to make a problem, and is fixed in one second, but only if it is reported properly.
—SA
Philippe Mori 10-Sep-15 12:51pm    
Well, there are many valid reason to modify this method. Ideally, Microsoft should have add a call to a partial method here so that we don't have to modify that compiler generated file.

I often add a partial void PreDispose() method when I want to do some extra cleanup (mostly either unhook events handlers or closing files or databases that are associated with a particular child Windows (tabbed MDI in my case).
Sergey Alexandrovich Kryukov 10-Sep-15 13:09pm    
Oh yes, of course, no doubt at all. I only tried to collect some information. As I say, with a full project, the "issue" could be a problem solved in a second. Something is messed up here; I cannot even trust than the code fragment shown is the same as in the real project.
—SA

1 solution

sorry, i don't know, whether the problem is already solved. if so, ignore me.

To me it seems, you try to override void Dispose(bool), to perform some action.
That is not scheduled, since the Designer-Code already did override it.

A usual approach is to subscribe the Form.Disposed-Event, to perform some action in the moment, when the form gets disposed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900