Reputation: 523
I'm using Visual C# 2008 Express. This is the first time I've had this error in years, the last time I had it was around the time I started programming.
I have no idea what it actually means or why it suddenly came up, it seems rather ambiguous for what the error message says. All I know is that throughout my app, I inherit a lot of the main windows from a ThemedWindow class I came up with to give them a custom appearance, there are no errors in that code and everything was working 100% perfect 20 minutes ago.
The error in full:
Warning 12 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:
InheritingWindow --- The base class 'ThemedWindow' could not be loaded. Ensure the assembly has been referenced and that all projects have been built. 0 0
I get that for every form that inherits from ThemedWindow, and several other errors because the project won't build far enough for everything else to work.
Just before this happened I updated the font on all forms and sub-controls, the project even built and ran after I did that, then this happened for absolutely no clear reason.
I've tried the classic rebuild it, delete build files, reopen Visual Studio etc, but nothing seems to work at the moment.
Does anyone know how to fix this?
Upvotes: 8
Views: 15406
Reputation: 99
As of writing this, this seems to be working properly in VS 2019 16.11.13.
It is not, however, working in VS 2022 17.1.6...
In VS 2022, I tried all the other fixes mentioned here, or they were not relevant:
AnyCPU is already set on the solution, never changed from that
The base class was never modified since it last worked, and so wouldn't need to recompile (plus this seems a moot point since it works fine in VS 2019)
While changing the base class temporarily to System.Windows.Forms.Form did get rid of the original error, it popped up a load of other errors of missing framework references and other non-problems.
The project is referencing .Net 4.8, (latest at time of writing this) and is not different from VS 2019 to VS 2022. Either way, can't reference non-existent newer version, and I doubt referencing an older version would fix this without breaking much more.
I saw a fix somewhere else of running VS as administrator and then rebuilding. This also did not fix the issue.
Upvotes: 4
Reputation: 390
I have this problem too, with VS 2019 version 16.11.2, so I guess this bug will never be fixed.
My workaround, since my BaseForm class does all its work through code at runtime and has no functionality that would affect the designer, is that when I need to use the designer, I just temporarily change my window's base class. That is, change--
partial class MainWindow : BaseForm {
to
partial class MainWindow : Form {
then do the design stuff, and then once the designer is closed, put BaseForm back.
This may work for you if your base form class also doesn't do anything that would have an effect in the designer.
Upvotes: 0
Reputation: 658
In my case (VS 2015 Pro) none of the above helped. Only after changing the target framework to different (specifically newer, from 4.5.1 to 4.5.2) and recompiling did the Forms Editor load the form.
Before changing the target framework I tried cleaning the solution, removing and adding the references (the base user control was in different dll), manually deleting all bin and obj folders after cleaning the project, restarting VS, all to no avail...
Upvotes: 0
Reputation: 523
These problems were caused by an unfortunate bug in Visual Studio. I had other errors (not warnings) in some code, even though nothing else directly depended upon it, which played a part in this whole situation.
I could be wrong in explaining it but here's what I think went wrong: for some reason (bug), it totally forgot about unchanged objects it had already compiled before, gave me the actual errors I had in my code, and a bunch of other warnings because it wouldn't go past that point. I couldn't get into the designer for forms that depended upon ThemedWindow
because I'm guessing ThemedWindow
hadn't recompiled before these errors occurred.
Once I commented out the erroneous code as a quick fix and rebuilt the solution, everything compiled successfully.
Upvotes: 3