-3

I need to change the Inherits statement in my class initialization file to

Inherits FileSystemWatcher

but I have found that this disables the

System.Windows.Forms.Form

references in my file and gives me debug errors for missing method references. The initialization file also does not accept the

Inherits FileSystemWatcher

statement.

I have tried to import

System.Windows.Forms.Form

on the initialization file, but this does not resolve the reference issues in the file. I have found that

System.Window.Forms.Form

must be in the inherits statement of the initialization file.

I seems to me that there are two issues: the base class in the primary file and the initialization file have to be the same, and the Windows Forms namespace must be used in the initialization file to make valid references for the methods used in the file.

How do I overcome these obstacles so that I can use the FileSystemWatcher inherit statement in my primary class?

KGCole
  • 11
  • 7
  • Firstly, *"it doesn't accept this"* is not an adequate explanation. You **ALWAYS** need to describe **EXACTLY** what happens. If there's an error message, it is provided for diagnostic purposes so, if you want us to diagnose the issue, logic dictates that you pass that message on to us, along with **ALL** other relevant information. How you ended up having this partial class in the first place would be relevant information. If it was auto-generated then how, because changing the base class of an auto-generated type often would not make sense. In short, provide a FULL and CLEAR explanation. – jmcilhinney Sep 19 '18 at 02:47
  • My first guess would be that you have created a form. If so, the class MUST inherit `Form`, either directly or indirectly. You can't inherit two base classes so if you want the functionality of a form then inheriting something other than `Form` isn't an option unless the new base class is also a form. – jmcilhinney Sep 19 '18 at 02:50
  • Update: Issue solved....imported several system classes on the initialization code page that I won't name here, but they enabled me to make the inherit statement for FileSystemWatcher. – KGCole Sep 19 '18 at 03:06
  • 1
    So it sounds like the issue was that you had not imported the `System.IO` namespace. To be a good citizen of this community, you should update your question so that it meets the standards of the site, then add your own answer that contains the solution. Vague questions with no proper answer don't help anyone else so should not be left visible. If you don't want to spend the time cleaning up this thread to potentially help others, you should delete your question. – jmcilhinney Sep 19 '18 at 03:09
  • @jmcilhinney although I solved the issue I was having with the base class, I had an error loading the form designer with Visual Studio. I didn't write the error code down, but closed my solution without saving hoping to revert back to the previous save. Unfortunately, I had data loss and some class involved with my form was lost...for instance, even the Load method is not now supported in my form (there's a squiggly red line under every method now not supported) This includes major methods such as Controls. Do you have any idea what may be missing now? I may need to make a new post for this. – KGCole Sep 19 '18 at 03:13
  • It sounds like you changed your form's class and removed the inheritance of the `Form` base class. See the second comment by @jmcilhinney. In short, your form class in the .designer.vb file must include the line `Inherits System.Windows.Forms.Form` after the form's declaration. – Chris Dunaway Sep 19 '18 at 16:12

1 Answers1

-2

This issue was solved importing relevant namespaces. jmcilhinney suggests it was the System.IO namespace. Once I had that imported, I was able to use the statement Inherits FileSystemWatcher, which is what I needed to reference the classes in the method I was using. Another issue was that the reference to inheritance of the base class has to be the same in the primary class as well as any partial class, otherwise Visual Studio will flag an error that the base classes are not the same.

KGCole
  • 11
  • 7
  • So the issue really had nothing to do with partial classes or inheritance and purely comes down to the fact that you have to specify the namespace of every type you use. In this case, you could use `System.IO.FileSystemWatcher` regardless of namespace imports. Because the `System` namespace is imported by default, you could also use `IO.FileSystemWatcher`. If you import the `System.IO` namespace at the file or project level then you can use the type name unqualified. – jmcilhinney Sep 19 '18 at 03:32
  • You can see which namespaces are imported project-wide and import more on the References page of the project properties. You can always import at the file level but, if you plan to use a namespace extensively throughout the project, I'd always recommend importing at the project level. – jmcilhinney Sep 19 '18 at 03:33
  • I don't think that's correct jmcilhinney. The error I received was specifically related to the base class used in the partial class, which has to be the same as the class you're trying to inherit in the primary code page. As you said, you can only inherit one base class, so the reference in the partial class has to be the same as in the primary. I'm not familiar, though, with the References page of the project properties. I'll have to look that up and see if I can find where you're talking about. – KGCole Sep 19 '18 at 03:43
  • You really ought to delete this whole thread. Your question doesn't provide relevant details and your answer doesn't actually address the issue that you're indicating that you had. It's good that you solved your problem but this thread won't help others. – jmcilhinney Sep 19 '18 at 03:46
  • I disagree. The answer I posted to the initial question specifically points out that it's important to have the proper namespace referenced in order to inherit the class desired. I think that's helpful. If you don't like the thread, vote it down. – KGCole Sep 19 '18 at 03:53
  • If the issue doesn't go away by importing the namespace then it's not an answer. – jmcilhinney Sep 19 '18 at 03:56
  • The issue did go away when the proper namespace was imported. – KGCole Sep 19 '18 at 04:05
  • Then why did you say that you thought that I was incorrect when I said that the issue was just the namespace and nothing to do with inheritance or partial classes? Either it was more than just the namespace, in which case this "answer" is not an answer, or it wasn't. Please start making sense. – jmcilhinney Sep 19 '18 at 04:17
  • I'm making sense. The issue was both. The namespace, and the partial class inheritance statement. The inheritance statement had to be identical in both the primary, and the partial class. That was one issue. The other issue was using the proper name space. I don't see why we need to belabor the point. Readers can see the issues for themselves. – KGCole Sep 19 '18 at 04:28
  • *"The issue was both"*. Then an answer needs to address both. Anything that doesn't address the actual issue in the question is not an answer. – jmcilhinney Sep 19 '18 at 04:34