Inheritance problem with System.Windows.Forms.Form

Viewed 134

I'm studying an older UI customization project (VB.NET Windows forms) by someone else and seem to be running into some kind of problem relating to inheritance. I can duplicate the issue easily, as I'll show, but why I'm baffled is that the project I'm studying is coded the exact same way but doesn't seem affected by this.

Example Code

Let's say we want to create our own form class like so, which would have special properties, event handlers etc.:

Public Class MyFormBase
    Inherits System.Windows.Forms.Form
End Class

And then in both our Form1.vb and Form1.designer.vb, we add:

Inherits MyNamespace.MyFormBase

thus replacing the inheritance in Form1.designer.vb which previously said

Inherits System.Windows.Forms.Form

The Error Message

When I try to view the design view of Form1, it is blocked with this error:

The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: Form1 --- The base class 'MyFormBase' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.

But, It Works Here...

When I look at the code for the VB.NET Project I'm studying, it's coded exactly the same way, and yet it works/runs without any problem at all. They both inherit from RJMainForm:

form.designer.vb:

Partial Class MainFormDemo
    Inherits RJCodeUI_M1.RJMainForm

and form.vb:

Public Class MainFormDemo
    Inherits RJMainForm

He said that he created his project originally in VS2012. I tried making the Framework versions match (thus referencing the exact same library files), adding the exact same references etc.

Conclusion

Why does this work in his solution but not mine? I've been through every config file and everything else, but can't find any explanation.

UPDATE #1

The older project that I was learning from included the actual .vb class files, so I was referencing the classes in them when doing my inheritance.

As a test, I did what Jimi suggested and created an Inherited Form. But you have to reference a DLL, which I didn't have - I had several dozen .vb class files spread out over multiple directories. It took some doing, but I managed to turn all of that into a DLL and use it as the basis of an Inherited Form. This Inherited Form approach works without issue and is a great long term solution, since I can now re-use the DLL.

Unfortunately, this brings me no closer to understanding what the actual problem is in my original approach, so I'm still hoping someone will be able to explain what's wrong with my original example code.

0 Answers
Related